Skip to content

Commit

Permalink
core: pull images only when they are missing - closes #70
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeneas Rekkas (arekkas) committed Dec 5, 2016
1 parent 8445a82 commit e4828e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions dockertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ func (d *Pool) Run(repository, tag string, env []string) (*Resource, error) {
tag = "latest"
}

if err := d.Client.PullImage(dc.PullImageOptions{
Repository: repository,
Tag: tag,
}, dc.AuthConfiguration{}); err != nil {
return nil, errors.Wrap(err, "")
_, err := d.Client.InspectImage(fmt.Sprintf("%s:%s", repository, tag))
if err != nil {
if err := d.Client.PullImage(dc.PullImageOptions{
Repository: repository,
Tag: tag,
}, dc.AuthConfiguration{}); err != nil {
return nil, errors.Wrap(err, "")
}
}

c, err := d.Client.CreateContainer(dc.CreateContainerOptions{
Expand Down Expand Up @@ -121,7 +124,7 @@ func (d *Pool) Purge(r *Resource) error {
// Retry is an exponential backoff retry helper. You can use it to wait for e.g. mysql to boot up.
func (d *Pool) Retry(op func() error) error {
if d.MaxWait == 0 {
d.MaxWait = time.Minute / 2
d.MaxWait = time.Minute
}
bo := backoff.NewExponentialBackOff()
bo.MaxInterval = time.Second * 5
Expand Down
4 changes: 2 additions & 2 deletions dockertest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestMain(m *testing.M) {
}

func TestMySQL(t *testing.T) {
resource, err := pool.Run("mysql", "5.7", []string{"MYSQL_ROOT_PASSWORD=secret"})
resource, err := pool.Run("mysql", "5.6", []string{"MYSQL_ROOT_PASSWORD=secret"})
require.Nil(t, err)
assert.NotEmpty(t, resource.GetPort("3306/tcp"))

Expand All @@ -41,7 +41,7 @@ func TestMySQL(t *testing.T) {
}

func TestPostgres(t *testing.T) {
resource, err := pool.Run("postgres", "9.6", nil)
resource, err := pool.Run("postgres", "9.5", nil)
require.Nil(t, err)
assert.NotEmpty(t, resource.GetPort("5432/tcp"))

Expand Down

0 comments on commit e4828e8

Please sign in to comment.