Skip to content

Commit

Permalink
Merge 8ea2c2d into 0a82db1
Browse files Browse the repository at this point in the history
  • Loading branch information
pmenglund committed Feb 22, 2017
2 parents 0a82db1 + 8ea2c2d commit b22b799
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions dockertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package dockertest

import (
"fmt"
"os"
"runtime"
"time"

"github.com/cenk/backoff"
dc "github.com/fsouza/go-dockerclient"
"github.com/pkg/errors"
"time"
"runtime"
"os"
)

// Pool represents a connection to the docker API and is used to create and remove docker images.
Expand Down Expand Up @@ -40,11 +41,19 @@ func (r *Resource) GetPort(id string) string {
}

// NewPool creates a new pool. You can pass an empty string to use the default, which is taken from the environment
// variable DOCKER_URL or if that is not defined a sensible default for the operating system you are on.
// variable DOCKER_URL, or from docker-machine if the environment variable DOCKER_MACHINE_NAME is set,
// or if neither is defined a sensible default for the operating system you are on.
func NewPool(endpoint string) (*Pool, error) {
if endpoint == "" {
if os.Getenv("DOCKER_URL") != "" {
endpoint = os.Getenv("DOCKER_URL")
} else if os.Getenv("DOCKER_MACHINE_NAME") != "" {
client, err := dc.NewClientFromEnv()
if err != nil {
return nil, errors.Wrap(err, "")
}

return &Pool{Client: client}, nil
} else if runtime.GOOS == "windows" {
endpoint = "http://localhost:2375"
} else {
Expand Down Expand Up @@ -107,7 +116,6 @@ func (d *Pool) Run(repository, tag string, env []string) (*Resource, error) {
}, nil
}


// Purge removes a container and linked volumes from docker.
func (d *Pool) Purge(r *Resource) error {
if err := d.Client.KillContainer(dc.KillContainerOptions{ID: r.Container.ID}); err != nil {
Expand Down

0 comments on commit b22b799

Please sign in to comment.