Skip to content

Commit

Permalink
#8 Add support for 'pre' and 'post' fields on captain.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
dkapanidis committed Jun 20, 2015
1 parent 111cded commit f2a18a4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
25 changes: 25 additions & 0 deletions captain/captain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,33 @@ func RealMain() {
handleCmd()
}

// Pre function executes commands on pre section before build
func Pre(config Config, filter string) {
for _, value := range config.GetPreCommands() {
info("Running pre command: %s", value)
res := execute("bash", "-c", value)
if res != nil {
err("Pre execution returned non-zero status")
os.Exit(TestFailed)
}
}
}

// Post function executes commands on pre section after build
func Post(config Config, filter string) {
for _, value := range config.GetPostCommands() {
info("Running post command: %s", value)
res := execute("bash", "-c", value)
if res != nil {
err("Post execution returned non-zero status")
os.Exit(TestFailed)
}
}
}

// Build function compiles the Containers of the project
func Build(config Config, filter string) {
Pre(config, filter)
var images = config.GetImageNames()

if filter != "" {
Expand Down
26 changes: 24 additions & 2 deletions captain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
type Config interface {
GetImageNames() map[string]string
GetUnitTestCommands() []string
GetPreCommands() []string
GetPostCommands() []string
}

type configV1 struct {
Expand All @@ -34,8 +36,8 @@ type config map[string]project
type project struct {
Build string
Image string
Pre string
Post string
Pre []string
Post []string
Test []string
}

Expand Down Expand Up @@ -159,6 +161,26 @@ func (c *config) GetUnitTestCommands() []string {
return tests
}

func (c *config) GetPreCommands() []string {
var pre []string
for _,k := range *c {
for _,t := range k.Pre {
pre = append(pre, t)
}
}
return pre
}

func (c *config) GetPostCommands() []string {
var post []string
for _,k := range *c {
for _,t := range k.Post {
post = append(post, t)
}
}
return post
}

// Global list, how can I pass it to the visitor pattern?
var imagesMap = make(map[string]string)

Expand Down

0 comments on commit f2a18a4

Please sign in to comment.