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.
func (b *B) Remove(name string) {
b.client.StopContainer(name, 5)
b.client.KillContainer(name, "SIGKILL")
b.client.KillContainer(name, "9")
b.client.RemoveContainer(name, true, true)
}
@ -85,8 +85,8 @@ func (b *B) RemoveAll() {
b.Lock()
defer b.Unlock()
for _, name := range b.containers {
b.Remove(name)
for i := len(b.containers) - 1; i >= 0; i-- {
b.Remove(b.containers[i])
}
}

@ -39,6 +39,14 @@ func (b *Builder) RunNotify(build *B) error {
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.
func Load(conf *common.Config) *Builder {
var (

@ -54,13 +54,13 @@ func NewAmbassador(client dockerclient.Client) (_ *Ambassador, err error) {
// Destroy stops and deletes the ambassador container.
func (c *Ambassador) Destroy() error {
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)
}
// CreateContainer creates a container.
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
conf.Env = append(conf.Env, "affinity:container=="+c.name)

@ -37,12 +37,13 @@ func main() {
var contexts []*Context
// must cleanup after our build
defer func() {
var cleanup = func(contexts []*Context) {
for _, c := range contexts {
c.build.RemoveAll()
c.client.Destroy()
}
}()
}
defer cleanup(contexts)
// list of builds and builders for each item
// in the matrix
@ -67,6 +68,7 @@ func main() {
}
// run the builds
var exit int
for _, c := range contexts {
log.Printf("starting build %s", c.config.Axis)
err := c.builder.RunBuild(c.build)
@ -74,22 +76,49 @@ func main() {
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 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
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")
for _, c := range contexts {
log.WithField("exit_code", c.build.ExitCode()).Infoln(c.config.Axis)
}
// cleanup
cleanup(contexts)
// write exit code
for _, c := range contexts {
if c.build.ExitCode() != 0 {
os.Exit(c.build.ExitCode())
}
}
os.Exit(exit)
}
var repo = &common.Repo{
@ -115,7 +144,7 @@ build:
- cd redis
- go version
- go build
- go test -v
- go test
compose:
redis: