2016-05-09 18:28:49 +00:00
|
|
|
package transform
|
|
|
|
|
2016-05-13 05:14:33 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"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 {
|
2016-06-11 03:46:13 +00:00
|
|
|
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
|
|
|
|
}
|
2016-05-13 05:14:33 +00:00
|
|
|
if httpProxy != "" {
|
|
|
|
p.Environment["HTTP_PROXY"] = httpProxy
|
2016-11-03 18:57:19 +00:00
|
|
|
p.Environment["http_proxy"] = httpProxy
|
2016-05-13 05:14:33 +00:00
|
|
|
}
|
|
|
|
if httpsProxy != "" {
|
|
|
|
p.Environment["HTTPS_PROXY"] = httpsProxy
|
2016-11-03 18:57:19 +00:00
|
|
|
p.Environment["https_proxy"] = httpsProxy
|
2016-05-13 05:14:33 +00:00
|
|
|
}
|
|
|
|
if noProxy != "" {
|
|
|
|
p.Environment["NO_PROXY"] = noProxy
|
2016-11-03 18:57:19 +00:00
|
|
|
p.Environment["no_proxy"] = noProxy
|
2016-05-13 05:14:33 +00:00
|
|
|
}
|
2016-05-09 18:28:49 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|