diff --git a/docker/image.go b/docker/image.go index 9508d73f..e3a845a1 100644 --- a/docker/image.go +++ b/docker/image.go @@ -289,6 +289,7 @@ func (c *Client) PushImage(opts PushImageOptions, auth AuthConfiguration) error type PullImageOptions struct { Repository string `qs:"fromImage"` Tag string + Platform string // Only required for Docker Engine 1.9 or 1.10 w/ Remote API < 1.21 // and Docker Engine < 1.9 diff --git a/dockertest.go b/dockertest.go index 992e1465..353e4034 100644 --- a/dockertest.go +++ b/dockertest.go @@ -302,6 +302,7 @@ type RunOptions struct { Privileged bool User string Tty bool + Platform string } // BuildOptions is used to pass in optional parameters when building a container @@ -403,6 +404,7 @@ func (d *Pool) RunWithOptions(opts *RunOptions, hcOpts ...func(*dc.HostConfig)) if err := d.Client.PullImage(dc.PullImageOptions{ Repository: repository, Tag: tag, + Platform: opts.Platform, }, opts.Auth); err != nil { return nil, errors.Wrap(err, "") } @@ -620,7 +622,7 @@ func (d *Pool) NetworksByName(name string) ([]Network, error) { ) } } - + return foundNetworks, nil } diff --git a/dockertest_test.go b/dockertest_test.go index 29c00d15..dd4a8a36 100644 --- a/dockertest_test.go +++ b/dockertest_test.go @@ -13,6 +13,7 @@ import ( "testing" "time" + _ "github.com/go-sql-driver/mysql" _ "github.com/lib/pq" dc "github.com/ory/dockertest/v3/docker" "github.com/stretchr/testify/assert" @@ -79,6 +80,29 @@ func TestMongo(t *testing.T) { require.Nil(t, pool.Purge(resource)) } +func TestMysqlWithPlatform(t *testing.T) { + resource, err := pool.RunWithOptions(&RunOptions{ + Repository: "mysql", + Tag: "5.7", + Env: []string{"MYSQL_ROOT_PASSWORD=secret"}, + Platform: "", // Platform in the format os[/arch[/variant]] (e.g. linux/amd64). Default: "" + }) + require.Nil(t, err) + assert.NotEmpty(t, resource.GetPort("3306/tcp")) + + err = pool.Retry(func() error { + var err error + db, err := sql.Open("mysql", fmt.Sprintf("root:secret@(localhost:%s)/mysql", resource.GetPort("3306/tcp"))) + if err != nil { + return err + } + return db.Ping() + }) + require.Nil(t, err) + + require.Nil(t, pool.Purge(resource)) +} + func TestContainerWithName(t *testing.T) { resource, err := pool.RunWithOptions( &RunOptions{ diff --git a/go.mod b/go.mod index b8dedb3f..16d38023 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/docker/cli v20.10.12+incompatible github.com/docker/go-connections v0.4.0 github.com/docker/go-units v0.4.0 + github.com/go-sql-driver/mysql v1.6.0 github.com/lib/pq v0.0.0-20180327071824-d34b9ff171c2 github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 github.com/opencontainers/image-spec v1.0.2 diff --git a/go.sum b/go.sum index 6d7cdb12..901912ba 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,8 @@ github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= +github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=