Allow using key-value data
This commit is contained in:
parent
0f0aba7f82
commit
b34ee789bc
@ -159,11 +159,11 @@ func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
||||
Value: true,
|
||||
Destination: &settings.Build.LabelsAuto,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "args",
|
||||
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
|
||||
Usage: "sets custom build arguments for the build",
|
||||
Destination: &settings.Build.Args,
|
||||
Usage: "sets custom build arguments for the build. Must be a JSON string",
|
||||
Destination: &settings.Build.ArgsRaw,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "args-from-env",
|
||||
|
@ -58,6 +58,7 @@ type Build struct {
|
||||
LabelsAuto bool // Docker build auto labels
|
||||
Labels cli.StringSlice // Docker build labels
|
||||
Platforms cli.StringSlice // Docker build target platforms
|
||||
ArgsRaw string // Docker build args (as JSON)
|
||||
Args cli.StringSlice // Docker build args
|
||||
ArgsEnv cli.StringSlice // Docker build args from env
|
||||
Target string // Docker build target
|
||||
@ -87,6 +88,26 @@ func (l Login) anonymous() bool {
|
||||
return l.Username == "" || l.Password == ""
|
||||
}
|
||||
|
||||
// Parse the provided build args into b.Args
|
||||
func (b Build) BuildArgs() {
|
||||
if len(b.ArgsRaw) > 0 {
|
||||
buildArgsRaw := map[string]string{}
|
||||
err := json.Unmarshal([]byte(b.ArgsRaw), &buildArgsRaw)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to parse build args: %s", err)
|
||||
}
|
||||
|
||||
for key, value := range buildArgsRaw {
|
||||
b.Args = *cli.NewStringSlice(
|
||||
append(
|
||||
b.Args.Value(),
|
||||
fmt.Sprintf("%s=%s", key, value),
|
||||
)...,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Init initialise plugin settings
|
||||
func (p *Plugin) InitSettings() error {
|
||||
if p.settings.LoginsRaw != "" {
|
||||
@ -227,6 +248,8 @@ func (p *Plugin) writeBuildkitConfig() error {
|
||||
|
||||
// Execute provides the implementation of the plugin.
|
||||
func (p *Plugin) Execute() error {
|
||||
p.settings.Build.BuildArgs()
|
||||
|
||||
// start the Docker daemon server
|
||||
if !p.settings.Daemon.Disabled {
|
||||
// If no custom DNS value set start internal DNS server
|
||||
|
Loading…
Reference in New Issue
Block a user