From c0084d32b3b6842488db3899f5640ca950f2505a Mon Sep 17 00:00:00 2001 From: nashiox Date: Tue, 18 Feb 2020 12:06:58 +0900 Subject: [PATCH 1/4] Add build secret flag --- cmd/drone-docker/main.go | 6 ++++++ docker.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/cmd/drone-docker/main.go b/cmd/drone-docker/main.go index 946d9945..da185624 100644 --- a/cmd/drone-docker/main.go +++ b/cmd/drone-docker/main.go @@ -228,6 +228,11 @@ func main() { Usage: "additional host:IP mapping", EnvVar: "PLUGIN_ADD_HOST", }, + cli.StringFlag{ + Name: "secret", + Usage: "Secret file to expose to the build (only if BuildKit enabled): id=mysecret,src=/local/secret", + EnvVar: "PLUGIN_SECRET", + }, } if err := app.Run(os.Args); err != nil { @@ -263,6 +268,7 @@ func run(c *cli.Context) error { LabelSchema: c.StringSlice("label-schema"), NoCache: c.Bool("no-cache"), AddHost: c.StringSlice("add-host"), + Secret: c.String("secret"), }, Daemon: docker.Daemon{ Registry: c.String("docker.registry"), diff --git a/docker.go b/docker.go index be23616f..edf50c2b 100644 --- a/docker.go +++ b/docker.go @@ -53,6 +53,7 @@ type ( Labels []string // Label map NoCache bool // Docker build no-cache AddHost []string // Docker build add-host + Secret string // Docker build secret } // Plugin defines the Docker plugin parameters. @@ -222,6 +223,9 @@ func commandBuild(build Build) *exec.Cmd { if build.Target != "" { args = append(args, "--target", build.Target) } + if build.Secret != "" { + args = append(args, "--secret", build.Secret) + } labelSchema := []string{ "schema-version=1.0", From 4940a7f73a1c6ddac2f49f32d6c1c433c114a432 Mon Sep 17 00:00:00 2001 From: nashiox Date: Tue, 18 Feb 2020 23:50:39 +0900 Subject: [PATCH 2/4] Modify secret flag to slice --- cmd/drone-docker/main.go | 4 ++-- docker.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/drone-docker/main.go b/cmd/drone-docker/main.go index da185624..49b17f50 100644 --- a/cmd/drone-docker/main.go +++ b/cmd/drone-docker/main.go @@ -228,7 +228,7 @@ func main() { Usage: "additional host:IP mapping", EnvVar: "PLUGIN_ADD_HOST", }, - cli.StringFlag{ + cli.StringSliceFlag{ Name: "secret", Usage: "Secret file to expose to the build (only if BuildKit enabled): id=mysecret,src=/local/secret", EnvVar: "PLUGIN_SECRET", @@ -268,7 +268,7 @@ func run(c *cli.Context) error { LabelSchema: c.StringSlice("label-schema"), NoCache: c.Bool("no-cache"), AddHost: c.StringSlice("add-host"), - Secret: c.String("secret"), + Secrets: c.StringSlice("secret"), }, Daemon: docker.Daemon{ Registry: c.String("docker.registry"), diff --git a/docker.go b/docker.go index edf50c2b..06c921fa 100644 --- a/docker.go +++ b/docker.go @@ -53,7 +53,7 @@ type ( Labels []string // Label map NoCache bool // Docker build no-cache AddHost []string // Docker build add-host - Secret string // Docker build secret + Secrets []string // Docker build secret } // Plugin defines the Docker plugin parameters. @@ -223,8 +223,8 @@ func commandBuild(build Build) *exec.Cmd { if build.Target != "" { args = append(args, "--target", build.Target) } - if build.Secret != "" { - args = append(args, "--secret", build.Secret) + for _, secret := range build.Secrets { + args = append(args, "--secret", secret) } labelSchema := []string{ From 6ddb61bb5abe6baa67486e231f81df0b397dac86 Mon Sep 17 00:00:00 2001 From: nashiox Date: Thu, 29 Oct 2020 20:52:53 +0900 Subject: [PATCH 3/4] fix conflict --- docker.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/docker.go b/docker.go index 90a4b55b..4de85fa5 100644 --- a/docker.go +++ b/docker.go @@ -249,13 +249,10 @@ func commandBuild(build Build) *exec.Cmd { if build.Target != "" { args = append(args, "--target", build.Target) } -<<<<<<< HEAD for _, secret := range build.Secrets { args = append(args, "--secret", secret) -======= if build.Quiet { args = append(args, "--quiet") ->>>>>>> upstream/master } labelSchema := []string{ From 1d236a7380a87b76754e7436b8bdbccc3505b058 Mon Sep 17 00:00:00 2001 From: nashiox Date: Thu, 29 Oct 2020 21:01:41 +0900 Subject: [PATCH 4/4] fix syntax --- docker.go | 1 + 1 file changed, 1 insertion(+) diff --git a/docker.go b/docker.go index 4de85fa5..4b0a1b21 100644 --- a/docker.go +++ b/docker.go @@ -251,6 +251,7 @@ func commandBuild(build Build) *exec.Cmd { } for _, secret := range build.Secrets { args = append(args, "--secret", secret) + } if build.Quiet { args = append(args, "--quiet") }