Merge pull request #376 from tphoney/add_support_for_platform_flag

Add support for docker --platform flag
This commit is contained in:
Dan Wilson
2022-11-17 13:37:40 +00:00
committed by GitHub
3 changed files with 31 additions and 0 deletions

View File

@@ -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 {
@@ -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"),

View File

@@ -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.
@@ -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{

View File

@@ -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 {