Skip to content

Commit

Permalink
Fixes #8 Add support for 'pre' and 'post' fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dkapanidis committed Jun 21, 2015
1 parent 4460a77 commit 74566d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
13 changes: 7 additions & 6 deletions captain/captain.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func RealMain() {
}

// Pre function executes commands on pre section before build
func Pre(config Config) {
for _, value := range config.GetPreCommands() {
func Pre(config Config, image string) {
for _, value := range config.GetPreCommands(image) {
info("Running pre command: %s", value)
res := execute("bash", "-c", value)
if res != nil {
Expand All @@ -28,8 +28,8 @@ func Pre(config Config) {
}

// Post function executes commands on pre section after build
func Post(config Config) {
for _, value := range config.GetPostCommands() {
func Post(config Config, image string) {
for _, value := range config.GetPostCommands(image) {
info("Running post command: %s", value)
res := execute("bash", "-c", value)
if res != nil {
Expand All @@ -41,7 +41,6 @@ func Post(config Config) {

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

var rev = getRevision()
Expand All @@ -58,6 +57,7 @@ func Build(config Config) {
sort.Strings(keys)

for _, dockerfile := range keys {
Pre(config, dockerfile)
image := images[dockerfile]
// If no Git repo exist
if !isGit() {
Expand Down Expand Up @@ -118,13 +118,14 @@ func Build(config Config) {
}
}
}
Post(config, dockerfile)
}
}

// Test function executes the tests of the project
func Test(config Config) {
for _, value := range config.GetUnitTestCommands() {
info("Running unit test command: %s", value)
info("Running test command: %s", value)
res := execute("bash", "-c", value)
if res != nil {
err("Test execution returned non-zero status")
Expand Down
22 changes: 14 additions & 8 deletions captain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
type Config interface {
GetImageNames() map[string]string
GetUnitTestCommands() []string
GetPreCommands() []string
GetPostCommands() []string
GetPreCommands(image string) []string
GetPostCommands(image string) []string
FilterConfig(filter string) bool
}

Expand Down Expand Up @@ -162,21 +162,27 @@ func (c *config) GetUnitTestCommands() []string {
return tests
}

func (c *config) GetPreCommands() []string {
func (c *config) GetPreCommands(image string) []string {
var pre []string

for _,k := range *c {
for _,t := range k.Pre {
pre = append(pre, t)
if (k.Build == image) {
for _,t := range k.Pre {
pre = append(pre, t)
}
}
}
return pre
}

func (c *config) GetPostCommands() []string {
func (c *config) GetPostCommands(image string) []string {
var post []string

for _,k := range *c {
for _,t := range k.Post {
post = append(post, t)
if (k.Build == image) {
for _,t := range k.Post {
post = append(post, t)
}
}
}
return post
Expand Down

0 comments on commit 74566d6

Please sign in to comment.