Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for docker --platform flag #376

Merged
merged 1 commit into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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