harness-drone/yaml/transform/image.go

61 lines
1.5 KiB
Go
Raw Normal View History

2016-05-09 18:28:49 +00:00
package transform
import (
2016-07-22 15:53:36 +00:00
"fmt"
2016-05-09 18:28:49 +00:00
"path/filepath"
"strings"
"github.com/drone/drone/yaml"
)
2016-05-10 05:57:57 +00:00
// ImagePull transforms the Yaml to automatically pull the latest image.
2016-05-09 18:28:49 +00:00
func ImagePull(conf *yaml.Config, pull bool) error {
for _, plugin := range conf.Pipeline {
2016-05-10 05:57:57 +00:00
if !isPlugin(plugin) {
2016-05-09 18:28:49 +00:00
continue
}
plugin.Pull = pull
}
return nil
}
2016-05-10 05:57:57 +00:00
// ImageTag transforms the Yaml to use the :latest image tag when empty.
2016-05-09 18:28:49 +00:00
func ImageTag(conf *yaml.Config) error {
for _, image := range conf.Pipeline {
if !strings.Contains(image.Image, ":") {
image.Image = image.Image + ":latest"
}
}
for _, image := range conf.Services {
if !strings.Contains(image.Image, ":") {
image.Image = image.Image + ":latest"
}
}
return nil
}
2016-05-10 05:57:57 +00:00
// ImageEscalate transforms the Yaml to automatically enable privileged mode
// for a subset of white-listed plugins matching the given patterns.
2016-05-09 18:28:49 +00:00
func ImageEscalate(conf *yaml.Config, patterns []string) error {
for _, c := range conf.Pipeline {
for _, pattern := range patterns {
if ok, _ := filepath.Match(pattern, c.Image); ok {
if c.Detached {
return fmt.Errorf("Detached mode disabled for the %s plugin", c.Image)
}
if len(c.Entrypoint) != 0 {
return fmt.Errorf("Custom entrypoint disabled for the %s plugin", c.Image)
}
if len(c.Command) != 0 {
return fmt.Errorf("Custom command disabled for the %s plugin", c.Image)
}
2016-07-22 15:53:36 +00:00
if len(c.Commands) != 0 {
return fmt.Errorf("Custom commands disabled for the %s plugin", c.Image)
}
2016-05-09 18:28:49 +00:00
c.Privileged = true
}
}
}
return nil
}