Skip to content

Commit

Permalink
Merge pull request #376 from tphoney/add_support_for_platform_flag
Browse files Browse the repository at this point in the history
Add support for docker --platform flag
  • Loading branch information
d1wilko committed Nov 17, 2022
2 parents 0d40d7f + 5a691ae commit 12be10a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/drone-docker/main.go
Expand Up @@ -269,6 +269,11 @@ func main() {
Usage: "card path location to write to",
EnvVar: "DRONE_CARD_PATH",
},
cli.StringFlag{
Name: "platform",
Usage: "platform value to pass to docker",
EnvVar: "PLUGIN_PLATFORM",
},
}

if err := app.Run(os.Args); err != nil {
Expand Down Expand Up @@ -312,6 +317,7 @@ func run(c *cli.Context) error {
SecretFiles: c.StringSlice("secrets-from-file"),
AddHost: c.StringSlice("add-host"),
Quiet: c.Bool("quiet"),
Platform: c.String("platform"),
},
Daemon: docker.Daemon{
Registry: c.String("docker.registry"),
Expand Down
4 changes: 4 additions & 0 deletions docker.go
Expand Up @@ -63,6 +63,7 @@ type (
SecretFiles []string // Docker build secrets with file as source
AddHost []string // Docker build add-host
Quiet bool // Docker build quiet
Platform string // Docker build platform
}

// Plugin defines the Docker plugin parameters.
Expand Down Expand Up @@ -324,6 +325,9 @@ func commandBuild(build Build) *exec.Cmd {
if build.Quiet {
args = append(args, "--quiet")
}
if build.Platform != "" {
args = append(args, "--platform", build.Platform)
}

if build.AutoLabel {
labelSchema := []string{
Expand Down
21 changes: 21 additions & 0 deletions docker_test.go
Expand Up @@ -114,6 +114,27 @@ func TestCommandBuild(t *testing.T) {
".",
),
},
{
name: "platform argument",
build: Build{
Name: "plugins/drone-docker:latest",
Dockerfile: "Dockerfile",
Context: ".",
Platform: "test/platform",
},
want: exec.Command(
dockerExe,
"build",
"--rm=true",
"-f",
"Dockerfile",
"-t",
"plugins/drone-docker:latest",
".",
"--platform",
"test/platform",
),
},
}

for _, tc := range tcs {
Expand Down

0 comments on commit 12be10a

Please sign in to comment.