Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit b08866c

Browse files
authored
fix: add option to set additional build contexts (#116)
1 parent 734b782 commit b08866c

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

_docs/data/data.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ properties:
8989
type: string
9090
required: false
9191

92+
named_context:
93+
description: Set additional named [build contexts](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-context) (e.g., name=path).
94+
type: list
95+
required: false
96+
9297
tags:
9398
description: Set repository tags to use for the image. Tags can also be loaded from a `.tags` file.
9499
defaultValue: latest

cmd/drone-docker-buildx/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
128128
Destination: &settings.Build.Context,
129129
Category: category,
130130
},
131+
&cli.StringSliceFlag{
132+
Name: "named-context",
133+
EnvVars: []string{"PLUGIN_NAMED_CONTEXT"},
134+
Usage: "additional named build context",
135+
Destination: &settings.Build.NamedContext,
136+
Category: category,
137+
},
131138
&cli.StringSliceFlag{
132139
Name: "tags",
133140
EnvVars: []string{"PLUGIN_TAG", "PLUGIN_TAGS"},

plugin/docker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ func commandBuild(build Build, dryrun bool) *exec.Cmd {
117117
if build.Output != "" {
118118
args = append(args, "--output", build.Output)
119119
}
120+
for _, arg := range build.NamedContext.Value() {
121+
args = append(args, "--build-context", arg)
122+
}
120123

121124
if len(build.Platforms.Value()) > 0 {
122125
args = append(args, "--platform", strings.Join(build.Platforms.Value(), ","))

plugin/impl.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,26 @@ type Login struct {
4040

4141
// Build defines Docker build parameters.
4242
type Build struct {
43-
Ref string // Git commit ref
44-
Branch string // Git repository branch
45-
Dockerfile string // Docker build Dockerfile
46-
Context string // Docker build context
47-
TagsAuto bool // Docker build auto tag
48-
TagsSuffix string // Docker build tags with suffix
49-
Tags cli.StringSlice // Docker build tags
50-
Platforms cli.StringSlice // Docker build target platforms
51-
Args cli.StringSlice // Docker build args
52-
ArgsEnv cli.StringSlice // Docker build args from env
53-
Target string // Docker build target
54-
Pull bool // Docker build pull
55-
CacheFrom cli.StringSlice // Docker build cache-from
56-
Compress bool // Docker build compress
57-
Repo string // Docker build repository
58-
NoCache bool // Docker build no-cache
59-
AddHost cli.StringSlice // Docker build add-host
60-
Quiet bool // Docker build quiet
61-
Output string // Docker build output folder
43+
Ref string // Git commit ref
44+
Branch string // Git repository branch
45+
Dockerfile string // Docker build Dockerfile
46+
Context string // Docker build context
47+
TagsAuto bool // Docker build auto tag
48+
TagsSuffix string // Docker build tags with suffix
49+
Tags cli.StringSlice // Docker build tags
50+
Platforms cli.StringSlice // Docker build target platforms
51+
Args cli.StringSlice // Docker build args
52+
ArgsEnv cli.StringSlice // Docker build args from env
53+
Target string // Docker build target
54+
Pull bool // Docker build pull
55+
CacheFrom cli.StringSlice // Docker build cache-from
56+
Compress bool // Docker build compress
57+
Repo string // Docker build repository
58+
NoCache bool // Docker build no-cache
59+
AddHost cli.StringSlice // Docker build add-host
60+
Quiet bool // Docker build quiet
61+
Output string // Docker build output folder
62+
NamedContext cli.StringSlice // Docker build named context
6263
}
6364

6465
// Settings for the Plugin.

0 commit comments

Comments
 (0)