grim/convey

821100c43641
Parents 1174c2ee05af
Children 2909e17deafe
Preliminary support for aws codebuild. refs #160
--- a/config/loader.go Mon Jan 15 16:20:18 2018 -0600
+++ b/config/loader.go Mon Jan 15 22:15:08 2018 -0600
@@ -28,7 +28,7 @@
// Loader defines all the functions that a config loader needs to implement.
type Loader interface {
- Load(path, base string, data []byte, disableDeprecated bool) (*Config, error)
+ Load(path, base string, data []byte, options []string, disableDeprecated bool) (*Config, error)
LoadOverride(path, base string, data []byte, config *Config, disableDeprecated bool)
Filenames() []string
OverrideSuffix() string
@@ -63,7 +63,7 @@
// LoadFile will determine the file name and override file name and then
// call the loaders methods to load them.
-func LoadFile(file string, loader Loader, disableDeprecated bool) (*Config, error) {
+func LoadFile(file string, loader Loader, options []string, disableDeprecated bool) (*Config, error) {
// split the filename into our parts
path, base := filepath.Split(file)
@@ -72,7 +72,7 @@
return nil, fmt.Errorf("failed to read config file '%s'", file)
}
- cfg, err := loader.Load(path, base, data, disableDeprecated)
+ cfg, err := loader.Load(path, base, data, options, disableDeprecated)
if err != nil {
return cfg, err
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/docker/parser.go Mon Jan 15 22:15:08 2018 -0600
@@ -0,0 +1,121 @@
+// Convey
+// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package docker
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/alecthomas/kingpin"
+
+ "bitbucket.org/rw_grim/convey/tasks"
+)
+
+// ParseCommand is a super stripped down kingpin parser that will parse docker
+// command line options and return a convey task or an error
+func ParseCommand(argv []string) (tasks.Task, error) {
+ app := kingpin.New("", "")
+
+ login := app.Command("login", "")
+ loginUsername := login.Flag("username", "").Short('u').Default("").String()
+ loginPassword := login.Flag("password", "").Short('p').Default("").String()
+ loginServer := login.Arg("", "").String()
+
+ logout := app.Command("logout", "")
+ logoutServer := logout.Arg("", "").String()
+
+ build := app.Command("build", "")
+ buildTag := build.Flag("tag", "").Short('t').String()
+ buildContext := build.Arg("", "").String()
+
+ push := app.Command("push", "")
+ pushImage := push.Arg("", "").Required().String()
+
+ pull := app.Command("pull", "")
+ pullImage := pull.Arg("", "").Required().String()
+
+ rmi := app.Command("rmi", "")
+ rmi.Flag("--force", "").Short('f').Default("false").Bool()
+ rmiImage := rmi.Arg("", "").Required().String()
+
+ run := app.Command("run", "")
+ runEntryPoint := run.Flag("entrypoint", "").String()
+ runEnv := run.Flag("env", "").Short('e').Strings()
+ runImage := run.Arg("image", "").Required().String()
+ runWorkdir := run.Flag("workdir", "").Short('w').String()
+ runCommand := run.Arg("", "").Strings()
+
+ tag := app.Command("tag", "")
+ tagSource := tag.Arg("src", "").Required().String()
+ tagDestination := tag.Arg("dest", "").Required().String()
+
+ cmd, err := app.Parse(argv[1:])
+ if err != nil {
+ return nil, err
+ }
+
+ var task tasks.Task
+
+ switch cmd {
+ case "build":
+ task = &Build{
+ Tag: *buildTag,
+ Files: []string{*buildContext},
+ }
+ case "login":
+ task = &Login{
+ Username: *loginUsername,
+ Password: *loginPassword,
+ Server: *loginServer,
+ }
+ case "logout":
+ task = &Logout{
+ Server: *logoutServer,
+ }
+ case "pull":
+ task = &Pull{
+ Image: *pullImage,
+ }
+ case "push":
+ task = &Push{
+ Image: *pushImage,
+ }
+ case "rmi":
+ task = &Remove{
+ Image: *rmiImage,
+ }
+ case "run":
+ task = &Run{
+ Command: strings.Join(*runCommand, " "),
+ Image: *runImage,
+ EntryPoint: *runEntryPoint,
+ Environment: *runEnv,
+ WorkDir: *runWorkdir,
+ }
+ case "tag":
+ task = &Tag{
+ Source: *tagSource,
+ Destination: *tagDestination,
+ }
+ }
+
+ if task != nil {
+ return task, nil
+ }
+
+ return nil, fmt.Errorf("unable to parse docker command line '%v'", argv)
+}
--- a/loaders/bitbucket/docker-parser.go Mon Jan 15 16:20:18 2018 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,122 +0,0 @@
-// Convey
-// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-package bitbucket
-
-import (
- "fmt"
- "strings"
-
- "github.com/alecthomas/kingpin"
-
- "bitbucket.org/rw_grim/convey/docker"
- "bitbucket.org/rw_grim/convey/tasks"
-)
-
-// parseDockerCommand is a super stripped down kingpin parse that will parse
-// docker command line options and return a convey task or an error
-func parseDockerCommand(argv []string) (tasks.Task, error) {
- app := kingpin.New("", "")
-
- login := app.Command("login", "")
- loginUsername := login.Flag("username", "").Short('u').Default("").String()
- loginPassword := login.Flag("password", "").Short('p').Default("").String()
- loginServer := login.Arg("", "").String()
-
- logout := app.Command("logout", "")
- logoutServer := logout.Arg("", "").String()
-
- build := app.Command("build", "")
- buildTag := build.Flag("tag", "").Short('t').String()
- buildContext := build.Arg("", "").String()
-
- push := app.Command("push", "")
- pushImage := push.Arg("", "").Required().String()
-
- pull := app.Command("pull", "")
- pullImage := pull.Arg("", "").Required().String()
-
- rmi := app.Command("rmi", "")
- rmi.Flag("--force", "").Short('f').Default("false").Bool()
- rmiImage := rmi.Arg("", "").Required().String()
-
- run := app.Command("run", "")
- runEntryPoint := run.Flag("entrypoint", "").String()
- runEnv := run.Flag("env", "").Short('e').Strings()
- runImage := run.Arg("image", "").Required().String()
- runWorkdir := run.Flag("workdir", "").Short('w').String()
- runCommand := run.Arg("", "").Strings()
-
- tag := app.Command("tag", "")
- tagSource := tag.Arg("src", "").Required().String()
- tagDestination := tag.Arg("dest", "").Required().String()
-
- cmd, err := app.Parse(argv[1:])
- if err != nil {
- return nil, err
- }
-
- var task tasks.Task
-
- switch cmd {
- case "build":
- task = &docker.Build{
- Tag: *buildTag,
- Files: []string{*buildContext},
- }
- case "login":
- task = &docker.Login{
- Username: *loginUsername,
- Password: *loginPassword,
- Server: *loginServer,
- }
- case "logout":
- task = &docker.Logout{
- Server: *logoutServer,
- }
- case "pull":
- task = &docker.Pull{
- Image: *pullImage,
- }
- case "push":
- task = &docker.Push{
- Image: *pushImage,
- }
- case "rmi":
- task = &docker.Remove{
- Image: *rmiImage,
- }
- case "run":
- task = &docker.Run{
- Command: strings.Join(*runCommand, " "),
- Image: *runImage,
- EntryPoint: *runEntryPoint,
- Environment: *runEnv,
- WorkDir: *runWorkdir,
- }
- case "tag":
- task = &docker.Tag{
- Source: *tagSource,
- Destination: *tagDestination,
- }
- }
-
- if task != nil {
- return task, nil
- }
-
- return nil, fmt.Errorf("unable to parse docker command line '%v'", argv)
-}
--- a/loaders/bitbucket/loader.go Mon Jan 15 16:20:18 2018 -0600
+++ b/loaders/bitbucket/loader.go Mon Jan 15 22:15:08 2018 -0600
@@ -126,7 +126,7 @@
}
// now figure out what docker command we're running
- task, err := parseDockerCommand(argv)
+ task, err := docker.ParseCommand(argv)
if err != nil {
return err
}
@@ -173,7 +173,7 @@
}
// Load loads the given filename and returns a config.Config for it.
-func (l *Loader) Load(base, path string, data []byte, disableDeprecated bool) (*config.Config, error) {
+func (l *Loader) Load(base, path string, data []byte, options []string, disableDeprecated bool) (*config.Config, error) {
var pipeline bitbucketPipelines
err := yaml.Unmarshal(data, &pipeline)
if err != nil {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/loaders/codebuild/codebuild.go Mon Jan 15 22:15:08 2018 -0600
@@ -0,0 +1,19 @@
+// Convey
+// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+// Package codebuild contains the convey load for AWS CodeBuild
+// https://aws.amazon.com/codebuild/
+package codebuild
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/loaders/codebuild/codebuild_test.go Mon Jan 15 22:15:08 2018 -0600
@@ -0,0 +1,37 @@
+// Convey
+// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package codebuild
+
+import (
+ "testing"
+
+ "github.com/aphistic/sweet"
+ junit "github.com/aphistic/sweet-junit"
+ . "github.com/onsi/gomega"
+)
+
+type codebuildSuite struct{}
+
+func TestMain(m *testing.M) {
+ RegisterFailHandler(sweet.GomegaFail)
+
+ sweet.Run(m, func(s *sweet.S) {
+ s.RegisterPlugin(junit.NewPlugin())
+
+ s.AddSuite(&codebuildSuite{})
+ })
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/loaders/codebuild/loader.go Mon Jan 15 22:15:08 2018 -0600
@@ -0,0 +1,210 @@
+// Convey
+// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package codebuild
+
+import (
+ "fmt"
+ "path/filepath"
+ "strings"
+
+ "github.com/go-yaml/yaml"
+ "github.com/kballard/go-shellquote"
+
+ "bitbucket.org/rw_grim/convey/config"
+ "bitbucket.org/rw_grim/convey/docker"
+ "bitbucket.org/rw_grim/convey/plans"
+ "bitbucket.org/rw_grim/convey/stages"
+ "bitbucket.org/rw_grim/convey/state"
+ "bitbucket.org/rw_grim/convey/tasks"
+)
+
+type Loader struct{}
+
+func (l *Loader) Load(path, base string, data []byte, options []string, disableDeprecated bool) (*config.Config, error) {
+ var cb CodeBuild
+ err := yaml.Unmarshal(data, &cb)
+ if err != nil {
+ return nil, err
+ }
+
+ cfg := &config.Config{
+ Tasks: map[string]tasks.Task{
+ "import": &docker.Import{
+ Files: []string{"."},
+ },
+ },
+ Plans: map[string]plans.Plan{},
+ }
+
+ // create our plan and add our tasks
+ plan := plans.Plan{
+ Stages: []stages.Stage{
+ {
+ Name: "import",
+ Enabled: true,
+ Run: "on-success",
+ Tasks: []string{"import"},
+ },
+ },
+ }
+
+ // TODO put the right image here
+ err = l.addPhases(cb, cfg, "alpine:edge", &plan)
+ if err != nil {
+ return nil, err
+ }
+
+ l.createExportTask(cb, cfg, &plan)
+
+ cfg.Plans["default"] = plan
+
+ return cfg, nil
+}
+
+func (l *Loader) addPhase(cb CodeBuild, cfg *config.Config, phaseName, imageName string, plan *plans.Plan) error {
+ stage := stages.Stage{
+ Name: phaseName,
+ Enabled: true,
+ Run: "on-success",
+ }
+
+ phase, ok := cb.Phases[phaseName]
+ // ignore phases that are not in the yaml
+ if !ok {
+ return nil
+ }
+
+ currentScript := []string{}
+ last := -1
+
+ for idx, cmd := range phase.Commands {
+ argv, err := shellquote.Split(cmd)
+ if err != nil {
+ return err
+ }
+
+ if len(argv) == 0 {
+ continue
+ }
+
+ if strings.TrimSpace(argv[0]) == "docker" {
+ taskName := fmt.Sprintf("%s-%d", phaseName, idx)
+
+ if len(currentScript) > 0 {
+ // create and add the task
+ taskName := fmt.Sprintf("%s-%d", phaseName, idx-1)
+ cfg.Tasks[taskName] = &docker.Run{
+ Shell: "/bin/sh",
+ Script: currentScript,
+ Image: imageName,
+ }
+ stage.Tasks = append(stage.Tasks, taskName)
+
+ // reset our state
+ currentScript = []string{}
+ last = idx
+ }
+
+ task, err := docker.ParseCommand(argv)
+ if err != nil {
+ return err
+ }
+
+ cfg.Tasks[taskName] = task
+ stage.Tasks = append(stage.Tasks, taskName)
+
+ last = idx
+ } else {
+ currentScript = append(currentScript, cmd)
+ }
+ }
+
+ if len(currentScript) > 0 {
+ taskName := fmt.Sprintf("%s-%d", phaseName, last+1)
+ cfg.Tasks[taskName] = &docker.Run{
+ Shell: "/bin/sh",
+ Script: currentScript,
+ Image: imageName,
+ }
+ stage.Tasks = append(stage.Tasks, taskName)
+ }
+
+ plan.Stages = append(plan.Stages, stage)
+
+ return nil
+}
+
+func (l *Loader) addPhases(cb CodeBuild, cfg *config.Config, imageName string, plan *plans.Plan) error {
+ phases := []string{"install", "pre_build", "build", "post_build"}
+
+ // load all of the phases scripts into a single slice
+ for _, phase := range phases {
+ err := l.addPhase(cb, cfg, phase, imageName, plan)
+ if err != nil {
+ return err
+ }
+
+ }
+
+ return nil
+}
+
+func (l *Loader) createExportTask(cb CodeBuild, cfg *config.Config, plan *plans.Plan) {
+ if len(cb.Artifacts.Files) == 0 {
+ return
+ }
+
+ export := &docker.Export{
+ Files: cb.Artifacts.Files,
+ }
+
+ cfg.Tasks["artifacts"] = export
+
+ if cb.Artifacts.DiscardPaths == "yes" {
+ for idx, name := range cb.Artifacts.Files {
+ cb.Artifacts.Files[idx] = filepath.Base(name)
+ }
+ }
+
+ exportStage := stages.Stage{
+ Name: "artifacts",
+ Enabled: true,
+ Run: "on-success",
+ Tasks: []string{"artifacts"},
+ }
+
+ plan.Stages = append(plan.Stages, exportStage)
+}
+
+func (l *Loader) LoadOverride(path, base string, data []byte, config *config.Config, disableDeprecated bool) {
+}
+
+func (l *Loader) Filenames() []string {
+ return []string{"buildspec.yml"}
+}
+
+func (l *Loader) OverrideSuffix() string {
+ return ""
+}
+
+func (l *Loader) DefaultPlan() string {
+ return "default"
+}
+
+func (l *Loader) ResolvePlanName(plan string, cfg *config.Config, st *state.State) string {
+ return plan
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/loaders/codebuild/types.go Mon Jan 15 22:15:08 2018 -0600
@@ -0,0 +1,39 @@
+// Convey
+// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package codebuild
+
+type environment struct {
+ Variables map[string]string `yaml:"variables"`
+ ParameterStore map[string]string `yaml:"parameter-store"`
+}
+
+type phase struct {
+ Commands []string `yaml:"commands"`
+}
+
+type artifacts struct {
+ Files []string `yaml:"files"`
+ DiscardPaths string `yaml:"discard-paths"`
+ BaseDirectory string `yaml:"base-directory"`
+}
+
+type CodeBuild struct {
+ Version string `yaml:"version"`
+ Environment environment `yaml:"env"`
+ Phases map[string]phase `yaml:"phases"`
+ Artifacts artifacts `yaml:"artifacts"`
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/loaders/codebuild/unmarshal_test.go Mon Jan 15 22:15:08 2018 -0600
@@ -0,0 +1,100 @@
+// Convey
+// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package codebuild
+
+import (
+ "github.com/aphistic/sweet"
+ "github.com/go-yaml/yaml"
+ . "github.com/onsi/gomega"
+)
+
+func (c *codebuildSuite) TestUnmarshalSimple(t sweet.T) {
+ yamlData := `version: 0.2
+env:
+ variables:
+ JAVA_HOME: "/usr/lib/jvm/java-8-openjdk-amd64"
+ parameter-store:
+ LOGIN_PASSWORD: "dockerLoginPassword"
+phases:
+ install:
+ commands:
+ - apt-get update -y
+ - apt-get install -y maven
+ pre_build:
+ commands:
+ - echo Nothing to do in the pre_build phase...
+ build:
+ commands:
+ - echo Build started on $(date)
+ - mvn install
+ post_build:
+ commands:
+ - echo Build completed on $(date)
+artifacts:
+ files:
+ - target/messageUtil-1.0.jar
+ discard-paths: yes`
+
+ var actual CodeBuild
+ err := yaml.Unmarshal([]byte(yamlData), &actual)
+
+ Expect(err).To(BeNil())
+
+ expected := CodeBuild{
+ Version: "0.2",
+ Environment: environment{
+ Variables: map[string]string{
+ "JAVA_HOME": "/usr/lib/jvm/java-8-openjdk-amd64",
+ },
+ ParameterStore: map[string]string{
+ "LOGIN_PASSWORD": "dockerLoginPassword",
+ },
+ },
+ Phases: map[string]phase{
+ "install": {
+ Commands: []string{
+ "apt-get update -y",
+ "apt-get install -y maven",
+ },
+ },
+ "pre_build": {
+ Commands: []string{
+ "echo Nothing to do in the pre_build phase...",
+ },
+ },
+ "build": {
+ Commands: []string{
+ "echo Build started on $(date)",
+ "mvn install",
+ },
+ },
+ "post_build": {
+ Commands: []string{
+ "echo Build completed on $(date)",
+ },
+ },
+ },
+ Artifacts: artifacts{
+ Files: []string{
+ "target/messageUtil-1.0.jar",
+ },
+ DiscardPaths: "yes",
+ },
+ }
+
+ Expect(actual).To(Equal(expected))
+}
--- a/loaders/convey/convey.go Mon Jan 15 16:20:18 2018 -0600
+++ b/loaders/convey/convey.go Mon Jan 15 22:15:08 2018 -0600
@@ -63,7 +63,7 @@
fileLoader func(string, *Loader) (*cConfig.Config, error)
}
-func (l *Loader) loadBase(cfg config, path string, disableDeprecated bool) (*cConfig.Config, error) {
+func (l *Loader) loadBase(cfg config, path string, options []string, disableDeprecated bool) (*cConfig.Config, error) {
// see if we're extending something - partially load a base
// config object if so that we'll modify; otherwise use an
// empty base config object that we'll set in a similar way
@@ -75,7 +75,7 @@
extendsAbsName := filepath.Join(path, cfg.Extends)
l.depth++
- baseConfig, err := l.loadFile(extendsAbsName, disableDeprecated)
+ baseConfig, err := l.loadFile(extendsAbsName, options, disableDeprecated)
l.depth--
// We can safely ignore no plans and no tasks errors here
@@ -134,7 +134,7 @@
}
// Load loads the given filename and returns it as a config.Config.
-func (l *Loader) Load(path, base string, data []byte, disableDeprecated bool) (*cConfig.Config, error) {
+func (l *Loader) Load(path, base string, data []byte, options []string, disableDeprecated bool) (*cConfig.Config, error) {
if l.logger == nil {
l.logger = logging.NewAdapter("config loader")
}
@@ -147,7 +147,7 @@
}
// get our base config
- baseConfig, err := l.loadBase(cfg, path, disableDeprecated)
+ baseConfig, err := l.loadBase(cfg, path, options, disableDeprecated)
if err != nil {
return nil, err
}
@@ -289,9 +289,9 @@
}
// Load loads the given filename and returns it as a config.Config.
-func (l *Loader) loadFile(path string, disableDeprecated bool) (*cConfig.Config, error) {
+func (l *Loader) loadFile(path string, options []string, disableDeprecated bool) (*cConfig.Config, error) {
if l.fileLoader == nil {
- return cConfig.LoadFile(path, l, disableDeprecated)
+ return cConfig.LoadFile(path, l, options, disableDeprecated)
}
return l.fileLoader(path, l)
--- a/main.go Mon Jan 15 16:20:18 2018 -0600
+++ b/main.go Mon Jan 15 22:15:08 2018 -0600
@@ -29,6 +29,7 @@
"bitbucket.org/rw_grim/convey/config"
"bitbucket.org/rw_grim/convey/environment"
"bitbucket.org/rw_grim/convey/loaders/bitbucket"
+ "bitbucket.org/rw_grim/convey/loaders/codebuild"
"bitbucket.org/rw_grim/convey/loaders/convey"
"bitbucket.org/rw_grim/convey/logging"
"bitbucket.org/rw_grim/convey/runners"
@@ -44,7 +45,7 @@
app = kingpin.New("convey", "Convey is a container pipeline runner.").Version(version)
color = app.Flag("color", "Enable colorized output").Default("true").Bool()
- configLoader = app.Flag("config-loader", "Select the configuration loader").Short('l').Default("convey").Enum("convey", "bitbucket")
+ configLoader = app.Flag("config-loader", "Select the configuration loader").Short('l').Default("convey").Enum("convey", "bitbucket", "codebuild")
configFile = app.Flag("config", "The config file name to use").Short('f').String()
cpuShares = app.Flag("cpu-shares", "The amount of cpu shares to give to a run task").Short('c').String()
dockerConfig = app.Flag("docker-config", "Location of docker client config files").String()
@@ -57,6 +58,7 @@
planTimeout = app.Flag("timeout", "The maximum amount of time a plan can run. 0 to disable. Units must be specified.").Default("15m").Duration()
verbose = app.Flag("verbose", "Be more verbose").Short('v').Default("False").Bool()
disableDeprecated = app.Flag("disable-deprecated", "Allow the use of deprecated features").Default("False").Bool()
+ options = app.Flag("opt", "Options to pass to the config loader").Short('o').Strings()
// deprecated options
graphviz = app.Flag("graphviz", "Output a graphviz diagram of the config file").Short('g').Hidden().Default("False").Bool()
@@ -88,6 +90,8 @@
switch *configLoader {
case "bitbucket":
return &bitbucket.Loader{}
+ case "codebuild":
+ return &codebuild.Loader{}
default:
return &convey.Loader{}
}
@@ -187,7 +191,7 @@
return nil, "", err
}
- cfg, err := config.LoadFile(*configFile, loader, *disableDeprecated)
+ cfg, err := config.LoadFile(*configFile, loader, *options, *disableDeprecated)
if err != nil {
return nil, "", err
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/codebuild/buildspec.yml Mon Jan 15 22:15:08 2018 -0600
@@ -0,0 +1,35 @@
+version: 0.2
+
+env:
+ variables:
+ JAVA_HOME: "/usr/lib/jvm/java-8-openjdk-amd64"
+ parameter-store:
+ LOGIN_PASSWORD: "dockerLoginPassword"
+
+phases:
+ install:
+ commands:
+ - echo Entered the install phase...
+ - apt-get update -y
+ - apt-get install -y maven
+ pre_build:
+ commands:
+ - echo Entered the pre_build phase...
+ - docker login –u User –p $LOGIN_PASSWORD
+ build:
+ commands:
+ - echo Entered the build phase...
+ - echo Build started on `date`
+ - mvn install
+ post_build:
+ commands:
+ - echo Entered the post_build phase...
+ - echo Build completed on `date`
+artifacts:
+ files:
+ - target/messageUtil-1.0.jar
+ discard-paths: yes
+cache:
+ paths:
+ - '/root/.m2/**/*'
+