grim/convey

Handle loader options for code build, actually use the image option. Refs #160
--- a/loaders/codebuild/loader.go Sun Jan 21 00:24:55 2018 -0600
+++ b/loaders/codebuild/loader.go Sun Jan 21 21:44:40 2018 -0600
@@ -19,6 +19,7 @@
import (
"fmt"
"path/filepath"
+ "strings"
"github.com/go-yaml/yaml"
@@ -31,11 +32,62 @@
"bitbucket.org/rw_grim/convey/tasks"
)
-type Loader struct{}
+type Loader struct {
+ region string
+ image string
+ accountID string
+}
+
+func (l *Loader) loadOptions(options []string) error {
+ for _, opt := range options {
+ parts := strings.SplitN(opt, "=", 2)
+ if len(parts) != 2 {
+ return fmt.Errorf("invalid option '%s'", opt)
+ }
+
+ switch parts[0] {
+ case "region":
+ l.region = parts[1]
+ case "image":
+ l.image = parts[1]
+ case "account-id":
+ l.accountID = parts[1]
+ }
+ }
+
+ if l.image == "" {
+ return fmt.Errorf("no image specified")
+ }
+
+ return nil
+}
+
+// Need more input to figure out how this works.
+// func (l *Loader) loadDefaultEnvironment() []string {
+// return []string{
+// "AWS_DEFAULT_REGION=",
+// "AWS_REGION=" + l.region,
+// "CODEBUILD_BUILD_ARN=",
+// "CODEBUILD_BUILD_ID=",
+// "CODEBUILD_BUILD_IMAGE=" + l.image,
+// "CODEBUILD_BUILD_SUCCEEDING=1", // hard coded for now 1 for succeeding, 0 for failing
+// "CODEBUILD_INITIATOR=convey",
+// "CODEBUILD_KMS_KEY_ID=",
+// "CODEBUILD_RESOLVED_SOURCE_VERSION=",
+// "CODEBUILD_SOURCE_REPO_URL=",
+// "CODEBUILD_SOURCE_VERSION=",
+// "CODEBUILD_SRC_DIR=",
+// }
+// }
func (l *Loader) Load(path, base string, data []byte, options []string, disableDeprecated bool) (*config.Config, error) {
+ err := l.loadOptions(options)
+ if err != nil {
+ return nil, err
+ }
+
var cb CodeBuild
- err := yaml.Unmarshal(data, &cb)
+ err = yaml.Unmarshal(data, &cb)
if err != nil {
return nil, err
}
@@ -62,7 +114,7 @@
}
// TODO put the right image here
- err = l.addPhases(cb, cfg, "alpine:edge", &plan)
+ err = l.addPhases(cb, cfg, l.image, &plan)
if err != nil {
return nil, err
}