Skip to content

Commit 92c8c21

Browse files
authored
Pass --platform information into Container Create (#285)
1 parent 332f5e7 commit 92c8c21

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

cmd/modern/root/install/mssql-base.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ type MssqlBase struct {
4545
defaultContextName string
4646
collation string
4747

48-
name string
49-
hostname string
48+
name string
49+
hostname string
50+
architecture string
51+
os string
5052

5153
port int
5254

@@ -173,6 +175,20 @@ func (c *MssqlBase) AddFlags(
173175
Usage: "Explicitly set the container hostname, it defaults to the container ID",
174176
})
175177

178+
addFlag(cmdparser.FlagOptions{
179+
String: &c.architecture,
180+
DefaultString: "amd64",
181+
Name: "architecture",
182+
Usage: "Specifies the image CPU architecture",
183+
})
184+
185+
addFlag(cmdparser.FlagOptions{
186+
String: &c.os,
187+
DefaultString: "linux",
188+
Name: "os",
189+
Usage: "Specifies the image operating system",
190+
})
191+
176192
addFlag(cmdparser.FlagOptions{
177193
String: &c.collation,
178194
DefaultString: "SQL_Latin1_General_CP1_CI_AS",
@@ -272,6 +288,8 @@ func (c *MssqlBase) createContainer(imageName string, contextName string) {
272288
c.port,
273289
c.name,
274290
c.hostname,
291+
c.architecture,
292+
c.os,
275293
[]string{},
276294
false,
277295
)

internal/container/controller.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/docker/docker/client"
1414
"github.com/docker/docker/pkg/stdcopy"
1515
"github.com/docker/go-connections/nat"
16+
specs "github.com/opencontainers/image-spec/specs-go/v1"
1617
"io"
1718
"path/filepath"
1819
"strconv"
@@ -71,6 +72,8 @@ func (c Controller) ContainerRun(
7172
port int,
7273
name string,
7374
hostname string,
75+
architecture string,
76+
os string,
7477
command []string,
7578
unitTestFailure bool,
7679
) string {
@@ -85,14 +88,18 @@ func (c Controller) ContainerRun(
8588
},
8689
}
8790

91+
platform := specs.Platform{
92+
Architecture: architecture,
93+
OS: os,
94+
}
95+
8896
resp, err := c.cli.ContainerCreate(context.Background(), &container.Config{
89-
Tty: true,
90-
Image: image,
91-
Cmd: command,
92-
Env: env,
93-
Hostname: hostname,
94-
Domainname: name,
95-
}, hostConfig, nil, nil, "")
97+
Tty: true,
98+
Image: image,
99+
Cmd: command,
100+
Env: env,
101+
Hostname: hostname,
102+
}, hostConfig, nil, &platform, name)
96103
checkErr(err)
97104

98105
err = c.cli.ContainerStart(

internal/container/controller_test.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ func TestController_EnsureImage(t *testing.T) {
3333
c := NewController()
3434
err := c.EnsureImage(imageName)
3535
checkErr(err)
36-
id := c.ContainerRun(imageName, []string{}, port, "", "", []string{"ash", "-c", "echo 'Hello World'; sleep 3"}, false)
36+
id := c.ContainerRun(
37+
imageName,
38+
[]string{},
39+
port,
40+
"",
41+
"",
42+
"amd64",
43+
"linux",
44+
[]string{"ash", "-c", "echo 'Hello World'; sleep 3"},
45+
false,
46+
)
3747
c.ContainerRunning(id)
3848
c.ContainerWaitForLogEntry(id, "Hello World")
3949
c.ContainerExists(id)
@@ -76,6 +86,8 @@ func TestController_ContainerRunFailure(t *testing.T) {
7686
0,
7787
"",
7888
"",
89+
"amd64",
90+
"linux",
7991
[]string{"ash", "-c", "echo 'Hello World'; sleep 1"},
8092
false,
8193
)
@@ -102,6 +114,8 @@ func TestController_ContainerRunFailureCleanup(t *testing.T) {
102114
0,
103115
"",
104116
"",
117+
"amd64",
118+
"linux",
105119
[]string{"ash", "-c", "echo 'Hello World'; sleep 1"},
106120
true,
107121
)

0 commit comments

Comments
 (0)