Skip to content

Commit

Permalink
feat: add platform field to run options to support Apple M1 (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
tainguyentt committed Mar 22, 2022
1 parent 593d31d commit ef54b32
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions docker/image.go
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion dockertest.go
Expand Up @@ -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
Expand Down Expand Up @@ -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, "")
}
Expand Down Expand Up @@ -620,7 +622,7 @@ func (d *Pool) NetworksByName(name string) ([]Network, error) {
)
}
}

return foundNetworks, nil
}

Expand Down
24 changes: 24 additions & 0 deletions dockertest_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -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=
Expand Down

0 comments on commit ef54b32

Please sign in to comment.