From b08866cc0bdb63e775db98ec203f0f3cebd7fe48 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 24 Jul 2022 12:48:02 +0200 Subject: [PATCH] fix: add option to set additional build contexts (#116) --- _docs/data/data.yaml | 5 ++++ cmd/drone-docker-buildx/config.go | 7 ++++++ plugin/docker.go | 3 +++ plugin/impl.go | 39 ++++++++++++++++--------------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/_docs/data/data.yaml b/_docs/data/data.yaml index af35d24..7621dcd 100644 --- a/_docs/data/data.yaml +++ b/_docs/data/data.yaml @@ -89,6 +89,11 @@ properties: type: string required: false + named_context: + description: Set additional named [build contexts](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-context) (e.g., name=path). + type: list + required: false + tags: description: Set repository tags to use for the image. Tags can also be loaded from a `.tags` file. defaultValue: latest diff --git a/cmd/drone-docker-buildx/config.go b/cmd/drone-docker-buildx/config.go index 189b9f1..f92c4c8 100644 --- a/cmd/drone-docker-buildx/config.go +++ b/cmd/drone-docker-buildx/config.go @@ -128,6 +128,13 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag { Destination: &settings.Build.Context, Category: category, }, + &cli.StringSliceFlag{ + Name: "named-context", + EnvVars: []string{"PLUGIN_NAMED_CONTEXT"}, + Usage: "additional named build context", + Destination: &settings.Build.NamedContext, + Category: category, + }, &cli.StringSliceFlag{ Name: "tags", EnvVars: []string{"PLUGIN_TAG", "PLUGIN_TAGS"}, diff --git a/plugin/docker.go b/plugin/docker.go index 6e5e81a..dc56d9a 100644 --- a/plugin/docker.go +++ b/plugin/docker.go @@ -117,6 +117,9 @@ func commandBuild(build Build, dryrun bool) *exec.Cmd { if build.Output != "" { args = append(args, "--output", build.Output) } + for _, arg := range build.NamedContext.Value() { + args = append(args, "--build-context", arg) + } if len(build.Platforms.Value()) > 0 { args = append(args, "--platform", strings.Join(build.Platforms.Value(), ",")) diff --git a/plugin/impl.go b/plugin/impl.go index 3690d54..d2921df 100644 --- a/plugin/impl.go +++ b/plugin/impl.go @@ -40,25 +40,26 @@ type Login struct { // Build defines Docker build parameters. type Build struct { - Ref string // Git commit ref - Branch string // Git repository branch - Dockerfile string // Docker build Dockerfile - Context string // Docker build context - TagsAuto bool // Docker build auto tag - TagsSuffix string // Docker build tags with suffix - Tags cli.StringSlice // Docker build tags - Platforms cli.StringSlice // Docker build target platforms - Args cli.StringSlice // Docker build args - ArgsEnv cli.StringSlice // Docker build args from env - Target string // Docker build target - Pull bool // Docker build pull - CacheFrom cli.StringSlice // Docker build cache-from - Compress bool // Docker build compress - Repo string // Docker build repository - NoCache bool // Docker build no-cache - AddHost cli.StringSlice // Docker build add-host - Quiet bool // Docker build quiet - Output string // Docker build output folder + Ref string // Git commit ref + Branch string // Git repository branch + Dockerfile string // Docker build Dockerfile + Context string // Docker build context + TagsAuto bool // Docker build auto tag + TagsSuffix string // Docker build tags with suffix + Tags cli.StringSlice // Docker build tags + Platforms cli.StringSlice // Docker build target platforms + Args cli.StringSlice // Docker build args + ArgsEnv cli.StringSlice // Docker build args from env + Target string // Docker build target + Pull bool // Docker build pull + CacheFrom cli.StringSlice // Docker build cache-from + Compress bool // Docker build compress + Repo string // Docker build repository + NoCache bool // Docker build no-cache + AddHost cli.StringSlice // Docker build add-host + Quiet bool // Docker build quiet + Output string // Docker build output folder + NamedContext cli.StringSlice // Docker build named context } // Settings for the Plugin.