|
59 | 59 | Link string // Git repo link |
60 | 60 | NoCache bool // Docker build no-cache |
61 | 61 | Secret string // secret keypair |
| 62 | + SecretEnvs []string // Docker build secrets with env var as source |
| 63 | + SecretFiles []string // Docker build secrets with file as source |
62 | 64 | AddHost []string // Docker build add-host |
63 | 65 | Quiet bool // Docker build quiet |
64 | 66 | } |
@@ -306,6 +308,16 @@ func commandBuild(build Build) *exec.Cmd { |
306 | 308 | if build.Secret != "" { |
307 | 309 | args = append(args, "--secret", build.Secret) |
308 | 310 | } |
| 311 | + for _, secret := range build.SecretEnvs { |
| 312 | + if arg, err := getSecretStringCmdArg(secret); err == nil { |
| 313 | + args = append(args, "--secret", arg) |
| 314 | + } |
| 315 | + } |
| 316 | + for _, secret := range build.SecretFiles { |
| 317 | + if arg, err := getSecretFileCmdArg(secret); err == nil { |
| 318 | + args = append(args, "--secret", arg) |
| 319 | + } |
| 320 | + } |
309 | 321 | if build.Target != "" { |
310 | 322 | args = append(args, "--target", build.Target) |
311 | 323 | } |
@@ -338,12 +350,40 @@ func commandBuild(build Build) *exec.Cmd { |
338 | 350 | } |
339 | 351 |
|
340 | 352 | // we need to enable buildkit, for secret support |
341 | | - if build.Secret != "" { |
| 353 | + if build.Secret != "" || len(build.SecretEnvs) > 0 || len(build.SecretFiles) > 0 { |
342 | 354 | os.Setenv("DOCKER_BUILDKIT", "1") |
343 | 355 | } |
344 | 356 | return exec.Command(dockerExe, args...) |
345 | 357 | } |
346 | 358 |
|
| 359 | +func getSecretStringCmdArg(kvp string) (string, error) { |
| 360 | + return getSecretCmdArg(kvp, false) |
| 361 | +} |
| 362 | + |
| 363 | +func getSecretFileCmdArg(kvp string) (string, error) { |
| 364 | + return getSecretCmdArg(kvp, true) |
| 365 | +} |
| 366 | + |
| 367 | +func getSecretCmdArg(kvp string, file bool) (string, error) { |
| 368 | + delimIndex := strings.IndexByte(kvp, '=') |
| 369 | + if delimIndex == -1 { |
| 370 | + return "", fmt.Errorf("%s is not a valid secret", kvp) |
| 371 | + } |
| 372 | + |
| 373 | + key := kvp[:delimIndex] |
| 374 | + value := kvp[delimIndex+1:] |
| 375 | + |
| 376 | + if key == "" || value == "" { |
| 377 | + return "", fmt.Errorf("%s is not a valid secret", kvp) |
| 378 | + } |
| 379 | + |
| 380 | + if file { |
| 381 | + return fmt.Sprintf("id=%s,src=%s", key, value), nil |
| 382 | + } |
| 383 | + |
| 384 | + return fmt.Sprintf("id=%s,env=%s", key, value), nil |
| 385 | +} |
| 386 | + |
347 | 387 | // helper function to add proxy values from the environment |
348 | 388 | func addProxyBuildArgs(build *Build) { |
349 | 389 | addProxyValue(build, "http_proxy") |
|
0 commit comments