1
0
mirror of https://github.com/drone/drone-cli.git synced 2024-11-23 01:11:57 +01:00

runs deploy & notify steps when defined

This commit is contained in:
Brad Rydzewski 2015-03-15 17:32:08 -07:00
parent d52dcdcee7
commit 2edcb4e015
4 changed files with 50 additions and 13 deletions

@ -75,7 +75,7 @@ func (b *B) Inspect(name string) (*dockerclient.ContainerInfo, error) {
// Remove stops and removes the named Docker container. // Remove stops and removes the named Docker container.
func (b *B) Remove(name string) { func (b *B) Remove(name string) {
b.client.StopContainer(name, 5) b.client.StopContainer(name, 5)
b.client.KillContainer(name, "SIGKILL") b.client.KillContainer(name, "9")
b.client.RemoveContainer(name, true, true) b.client.RemoveContainer(name, true, true)
} }
@ -85,8 +85,8 @@ func (b *B) RemoveAll() {
b.Lock() b.Lock()
defer b.Unlock() defer b.Unlock()
for _, name := range b.containers { for i := len(b.containers) - 1; i >= 0; i-- {
b.Remove(name) b.Remove(b.containers[i])
} }
} }

@ -39,6 +39,14 @@ func (b *Builder) RunNotify(build *B) error {
return b.notify.Run(build) return b.notify.Run(build)
} }
func (b *Builder) HasDeploy() bool {
return len(b.deploy.(serialNode)) != 0
}
func (b *Builder) HasNotify() bool {
return len(b.notify.(serialNode)) != 0
}
// Load loads a build configuration file. // Load loads a build configuration file.
func Load(conf *common.Config) *Builder { func Load(conf *common.Config) *Builder {
var ( var (

@ -54,13 +54,13 @@ func NewAmbassador(client dockerclient.Client) (_ *Ambassador, err error) {
// Destroy stops and deletes the ambassador container. // Destroy stops and deletes the ambassador container.
func (c *Ambassador) Destroy() error { func (c *Ambassador) Destroy() error {
c.Client.StopContainer(c.name, 5) c.Client.StopContainer(c.name, 5)
c.Client.KillContainer(c.name, "SIGKILL") c.Client.KillContainer(c.name, "9")
return c.Client.RemoveContainer(c.name, true, true) return c.Client.RemoveContainer(c.name, true, true)
} }
// CreateContainer creates a container. // CreateContainer creates a container.
func (c *Ambassador) CreateContainer(conf *dockerclient.ContainerConfig, name string) (string, error) { func (c *Ambassador) CreateContainer(conf *dockerclient.ContainerConfig, name string) (string, error) {
log.WithField("image", conf.Image).Debugln("create container") log.WithField("image", conf.Image).Infoln("create container")
// add the affinity flag for swarm // add the affinity flag for swarm
conf.Env = append(conf.Env, "affinity:container=="+c.name) conf.Env = append(conf.Env, "affinity:container=="+c.name)

@ -37,12 +37,13 @@ func main() {
var contexts []*Context var contexts []*Context
// must cleanup after our build // must cleanup after our build
defer func() { var cleanup = func(contexts []*Context) {
for _, c := range contexts { for _, c := range contexts {
c.build.RemoveAll() c.build.RemoveAll()
c.client.Destroy() c.client.Destroy()
} }
}() }
defer cleanup(contexts)
// list of builds and builders for each item // list of builds and builders for each item
// in the matrix // in the matrix
@ -67,6 +68,7 @@ func main() {
} }
// run the builds // run the builds
var exit int
for _, c := range contexts { for _, c := range contexts {
log.Printf("starting build %s", c.config.Axis) log.Printf("starting build %s", c.config.Axis)
err := c.builder.RunBuild(c.build) err := c.builder.RunBuild(c.build)
@ -74,22 +76,49 @@ func main() {
c.build.Exit(255) c.build.Exit(255)
// TODO need a 255 exit code if the build errors // TODO need a 255 exit code if the build errors
} }
if c.build.ExitCode() != 0 {
exit = c.build.ExitCode()
}
} }
// run the deploy steps // run the deploy steps
if exit == 0 {
for _, c := range contexts {
if !c.builder.HasDeploy() {
continue
}
log.Printf("starting post-build tasks %s", c.config.Axis)
err := c.builder.RunDeploy(c.build)
if err != nil {
c.build.Exit(255)
// TODO need a 255 exit code if the build errors
}
if c.build.ExitCode() != 0 {
exit = c.build.ExitCode()
}
}
}
// run the notify steps // run the notify steps
for _, c := range contexts {
if !c.builder.HasNotify() {
continue
}
log.Printf("staring notification tasks %s", c.config.Axis)
c.builder.RunNotify(c.build)
break
}
log.Println("build complete") log.Println("build complete")
for _, c := range contexts { for _, c := range contexts {
log.WithField("exit_code", c.build.ExitCode()).Infoln(c.config.Axis) log.WithField("exit_code", c.build.ExitCode()).Infoln(c.config.Axis)
} }
// cleanup
cleanup(contexts)
// write exit code // write exit code
for _, c := range contexts { os.Exit(exit)
if c.build.ExitCode() != 0 {
os.Exit(c.build.ExitCode())
}
}
} }
var repo = &common.Repo{ var repo = &common.Repo{
@ -115,7 +144,7 @@ build:
- cd redis - cd redis
- go version - go version
- go build - go build
- go test -v - go test
compose: compose:
redis: redis: