woodpecker/yaml/transform/environ.go

48 lines
1 KiB
Go
Raw Normal View History

2016-05-09 18:28:49 +00:00
package transform
import (
"os"
"strings"
"github.com/drone/drone/yaml"
)
var (
httpProxy = os.Getenv("HTTP_PROXY")
httpsProxy = os.Getenv("HTTPS_PROXY")
noProxy = os.Getenv("NO_PROXY")
)
2016-05-09 18:28:49 +00:00
// Environ transforms the steps in the Yaml pipeline to include runtime
// environment variables.
func Environ(c *yaml.Config, envs map[string]string) error {
var images []*yaml.Container
images = append(images, c.Pipeline...)
images = append(images, c.Services...)
for _, p := range images {
2016-05-09 18:28:49 +00:00
if p.Environment == nil {
p.Environment = map[string]string{}
}
for k, v := range envs {
if v == "" {
continue
}
p.Environment[k] = v
}
if httpProxy != "" {
p.Environment["HTTP_PROXY"] = httpProxy
p.Environment["http_proxy"] = strings.ToUpper(httpProxy)
}
if httpsProxy != "" {
p.Environment["HTTPS_PROXY"] = httpsProxy
p.Environment["https_proxy"] = strings.ToUpper(httpsProxy)
}
if noProxy != "" {
p.Environment["NO_PROXY"] = noProxy
p.Environment["no_proxy"] = strings.ToUpper(noProxy)
}
2016-05-09 18:28:49 +00:00
}
return nil
}