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,
|
Value: true,
|
||||||
Destination: &settings.Build.LabelsAuto,
|
Destination: &settings.Build.LabelsAuto,
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringFlag{
|
||||||
Name: "args",
|
Name: "args",
|
||||||
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
|
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
|
||||||
Usage: "sets custom build arguments for the build",
|
Usage: "sets custom build arguments for the build. Must be a JSON string",
|
||||||
Destination: &settings.Build.Args,
|
Destination: &settings.Build.ArgsRaw,
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "args-from-env",
|
Name: "args-from-env",
|
||||||
|
@ -19,7 +19,7 @@ func main() {
|
|||||||
if _, err := os.Stat("/run/drone/env"); err == nil {
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||||
godotenv.Overload("/run/drone/env")
|
godotenv.Overload("/run/drone/env")
|
||||||
}
|
}
|
||||||
|
|
||||||
if envFile, set := os.LookupEnv("PLUGIN_ENV_FILE"); set {
|
if envFile, set := os.LookupEnv("PLUGIN_ENV_FILE"); set {
|
||||||
godotenv.Overload(envFile)
|
godotenv.Overload(envFile)
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ type Build struct {
|
|||||||
LabelsAuto bool // Docker build auto labels
|
LabelsAuto bool // Docker build auto labels
|
||||||
Labels cli.StringSlice // Docker build labels
|
Labels cli.StringSlice // Docker build labels
|
||||||
Platforms cli.StringSlice // Docker build target platforms
|
Platforms cli.StringSlice // Docker build target platforms
|
||||||
|
ArgsRaw string // Docker build args (as JSON)
|
||||||
Args cli.StringSlice // Docker build args
|
Args cli.StringSlice // Docker build args
|
||||||
ArgsEnv cli.StringSlice // Docker build args from env
|
ArgsEnv cli.StringSlice // Docker build args from env
|
||||||
Target string // Docker build target
|
Target string // Docker build target
|
||||||
@ -87,6 +88,26 @@ func (l Login) anonymous() bool {
|
|||||||
return l.Username == "" || l.Password == ""
|
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
|
// Init initialise plugin settings
|
||||||
func (p *Plugin) InitSettings() error {
|
func (p *Plugin) InitSettings() error {
|
||||||
if p.settings.LoginsRaw != "" {
|
if p.settings.LoginsRaw != "" {
|
||||||
@ -227,6 +248,8 @@ func (p *Plugin) writeBuildkitConfig() error {
|
|||||||
|
|
||||||
// Execute provides the implementation of the plugin.
|
// Execute provides the implementation of the plugin.
|
||||||
func (p *Plugin) Execute() error {
|
func (p *Plugin) Execute() error {
|
||||||
|
p.settings.Build.BuildArgs()
|
||||||
|
|
||||||
// start the Docker daemon server
|
// start the Docker daemon server
|
||||||
if !p.settings.Daemon.Disabled {
|
if !p.settings.Daemon.Disabled {
|
||||||
// If no custom DNS value set start internal DNS server
|
// If no custom DNS value set start internal DNS server
|
||||||
|
Loading…
Reference in New Issue
Block a user