diff --git a/app.go b/app.go index 7be5ba3..e3dcb26 100644 --- a/app.go +++ b/app.go @@ -147,6 +147,17 @@ func Run() { Usage: "build args", EnvVar: "PLUGIN_BUILD_ARGS_FROM_ENV", }, + cli.GenericFlag{ + Name: "args-new", + Usage: "build args new", + EnvVar: "PLUGIN_BUILD_ARGS_NEW", + Value: new(CustomStringSliceFlag), + }, + cli.BoolFlag{ + Name: "plugin-multiple-build-agrs", + Usage: "plugin multiple build agrs", + EnvVar: "PLUGIN_MULTIPLE_BUILD_ARGS", + }, cli.BoolFlag{ Name: "quiet", Usage: "quiet docker build", @@ -382,33 +393,35 @@ func run(c *cli.Context) error { ArtifactFile: c.String("artifact-file"), CacheMetricsFile: c.String("cache-metrics-file"), Build: Build{ - Remote: c.String("remote.url"), - Name: c.String("commit.sha"), - Dockerfile: c.String("dockerfile"), - Context: c.String("context"), - Tags: c.StringSlice("tags"), - Args: c.StringSlice("args"), - ArgsEnv: c.StringSlice("args-from-env"), - Target: c.String("target"), - Squash: c.Bool("squash"), - Pull: c.BoolT("pull-image"), - CacheFrom: c.Generic("cache-from").(*CustomStringSliceFlag).GetValue(), - CacheTo: c.Generic("cache-to").(*CustomStringSliceFlag).GetValue(), - Compress: c.Bool("compress"), - Repo: c.String("repo"), - Labels: c.StringSlice("custom-labels"), - LabelSchema: c.StringSlice("label-schema"), - AutoLabel: c.BoolT("auto-label"), - Link: c.String("link"), - NoCache: c.Bool("no-cache"), - Secret: c.String("secret"), - SecretEnvs: c.StringSlice("secrets-from-env"), - SecretFiles: c.StringSlice("secrets-from-file"), - AddHost: c.StringSlice("add-host"), - Quiet: c.Bool("quiet"), - Platform: c.String("platform"), - SSHAgentKey: c.String("ssh-agent-key"), - BuildxLoad: c.Bool("buildx-load"), + Remote: c.String("remote.url"), + Name: c.String("commit.sha"), + Dockerfile: c.String("dockerfile"), + Context: c.String("context"), + Tags: c.StringSlice("tags"), + Args: c.StringSlice("args"), + ArgsEnv: c.StringSlice("args-from-env"), + ArgsNew: c.Generic("args-new").(*CustomStringSliceFlag).GetValue(), + IsMultipleBuildArgs: c.Bool("plugin-multiple-build-agrs"), + Target: c.String("target"), + Squash: c.Bool("squash"), + Pull: c.BoolT("pull-image"), + CacheFrom: c.Generic("cache-from").(*CustomStringSliceFlag).GetValue(), + CacheTo: c.Generic("cache-to").(*CustomStringSliceFlag).GetValue(), + Compress: c.Bool("compress"), + Repo: c.String("repo"), + Labels: c.StringSlice("custom-labels"), + LabelSchema: c.StringSlice("label-schema"), + AutoLabel: c.BoolT("auto-label"), + Link: c.String("link"), + NoCache: c.Bool("no-cache"), + Secret: c.String("secret"), + SecretEnvs: c.StringSlice("secrets-from-env"), + SecretFiles: c.StringSlice("secrets-from-file"), + AddHost: c.StringSlice("add-host"), + Quiet: c.Bool("quiet"), + Platform: c.String("platform"), + SSHAgentKey: c.String("ssh-agent-key"), + BuildxLoad: c.Bool("buildx-load"), }, Daemon: Daemon{ Registry: c.String("docker.registry"), diff --git a/docker.go b/docker.go index 3065ca1..0cea80d 100644 --- a/docker.go +++ b/docker.go @@ -53,34 +53,36 @@ type ( // Build defines Docker build parameters. Build struct { - Remote string // Git remote URL - Name string // Docker build using default named tag - Dockerfile string // Docker build Dockerfile - Context string // Docker build context - Tags []string // Docker build tags - Args []string // Docker build args - ArgsEnv []string // Docker build args from env - Target string // Docker build target - Squash bool // Docker build squash - Pull bool // Docker build pull - CacheFrom []string // Docker buildx cache-from - CacheTo []string // Docker buildx cache-to - Compress bool // Docker build compress - Repo string // Docker build repository - LabelSchema []string // label-schema Label map - AutoLabel bool // auto-label bool - Labels []string // Label map - Link string // Git repo link - NoCache bool // Docker build no-cache - Secret string // secret keypair - SecretEnvs []string // Docker build secrets with env var as source - 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 - SSHAgentKey string // Docker build ssh agent key - SSHKeyPath string // Docker build ssh key path - BuildxLoad bool // Docker buildx --load + Remote string // Git remote URL + Name string // Docker build using default named tag + Dockerfile string // Docker build Dockerfile + Context string // Docker build context + Tags []string // Docker build tags + Args []string // Docker build args + ArgsEnv []string // Docker build args from env + ArgsNew []string // Docker build args with comma seperated values + IsMultipleBuildArgs bool // env variable for fall back + Target string // Docker build target + Squash bool // Docker build squash + Pull bool // Docker build pull + CacheFrom []string // Docker buildx cache-from + CacheTo []string // Docker buildx cache-to + Compress bool // Docker build compress + Repo string // Docker build repository + LabelSchema []string // label-schema Label map + AutoLabel bool // auto-label bool + Labels []string // Label map + Link string // Git repo link + NoCache bool // Docker build no-cache + Secret string // secret keypair + SecretEnvs []string // Docker build secrets with env var as source + 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 + SSHAgentKey string // Docker build ssh agent key + SSHKeyPath string // Docker build ssh key path + BuildxLoad bool // Docker buildx --load } // Plugin defines the Docker plugin parameters. @@ -512,8 +514,14 @@ func commandBuildx(build Build, builder Builder, dryrun bool, metadataFile strin for _, arg := range build.ArgsEnv { addProxyValue(&build, arg) } - for _, arg := range build.Args { - args = append(args, "--build-arg", arg) + if build.IsMultipleBuildArgs { + for _, arg := range build.ArgsNew { + args = append(args, "--build-arg", arg) + } + } else { + for _, arg := range build.Args { + args = append(args, "--build-arg", arg) + } } for _, host := range build.AddHost { args = append(args, "--add-host", host) @@ -613,6 +621,10 @@ func addProxyValue(build *Build, key string) { build.Args = append(build.Args, fmt.Sprintf("%s=%s", key, value)) build.Args = append(build.Args, fmt.Sprintf("%s=%s", strings.ToUpper(key), value)) } + if len(value) > 0 && !hasProxyBuildArgNew(build, key) { + build.ArgsNew = append(build.ArgsNew, fmt.Sprintf("%s=%s", key, value)) + build.ArgsNew = append(build.ArgsNew, fmt.Sprintf("%s=%s", strings.ToUpper(key), value)) + } } // helper function to get a proxy value from the environment. @@ -641,6 +653,17 @@ func hasProxyBuildArg(build *Build, key string) bool { return false } +func hasProxyBuildArgNew(build *Build, key string) bool { + keyUpper := strings.ToUpper(key) + + for _, s := range build.ArgsNew { + if strings.HasPrefix(s, key) || strings.HasPrefix(s, keyUpper) { + return true + } + } + return false +} + // helper function to create the docker tag command. func commandTag(build Build, tag string) *exec.Cmd { var (