support.go 874 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package builder
  2. import (
  3. "regexp"
  4. "strings"
  5. )
  6. var (
  7. TOKEN_ENV_INTERPOLATION = regexp.MustCompile("(\\\\\\\\+|[^\\\\]|\\b|\\A)\\$({?)([[:alnum:]_]+)(}?)")
  8. )
  9. // handle environment replacement. Used in dispatcher.
  10. func (b *Builder) replaceEnv(str string) string {
  11. for _, match := range TOKEN_ENV_INTERPOLATION.FindAllString(str, -1) {
  12. match = match[strings.Index(match, "$"):]
  13. matchKey := strings.Trim(match, "${}")
  14. for _, keyval := range b.Config.Env {
  15. tmp := strings.SplitN(keyval, "=", 2)
  16. if tmp[0] == matchKey {
  17. str = strings.Replace(str, match, tmp[1], -1)
  18. break
  19. }
  20. }
  21. }
  22. return str
  23. }
  24. func handleJsonArgs(args []string, attributes map[string]bool) []string {
  25. if attributes != nil && attributes["json"] {
  26. return args
  27. }
  28. // literal string command, not an exec array
  29. return append([]string{"/bin/sh", "-c", strings.Join(args, " ")})
  30. }