updating for latest data structure

This commit is contained in:
Brad Rydzewski 2015-09-30 12:37:32 -07:00
parent 9790f1a015
commit aa320db9c5
5 changed files with 61 additions and 43 deletions

View File

@ -16,7 +16,7 @@ import (
var ( var (
dotenv = flag.String("config", ".env", "") dotenv = flag.String("config", ".env", "")
debug = flag.Bool("debug", true, "") debug = flag.Bool("debug", false, "")
) )
func main() { func main() {

View File

@ -140,7 +140,7 @@ func (e *engine) Schedule(req *Task) {
const size = 64 << 10 const size = 64 << 10
buf := make([]byte, size) buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)] buf = buf[:runtime.Stack(buf, false)]
log.Printf("panic running build: %v\n%s", err, buf) log.Errorf("panic running build: %v\n%s", err, string(buf))
} }
e.pool.release(node) e.pool.release(node)
}() }()
@ -177,7 +177,7 @@ func (e *engine) Schedule(req *Task) {
runJob(req, e.updater, client) runJob(req, e.updater, client)
} }
// TODO // update overall status based on each job
req.Build.Status = model.StatusSuccess req.Build.Status = model.StatusSuccess
for _, job := range req.Jobs { for _, job := range req.Jobs {
if job.Status != model.StatusSuccess { if job.Status != model.StatusSuccess {
@ -191,14 +191,11 @@ func (e *engine) Schedule(req *Task) {
log.Errorf("error updating build completion status. %s", err) log.Errorf("error updating build completion status. %s", err)
} }
// run notifications!!! // run notifications
// for _ = range req.Jobs { err = runJobNotify(req, client)
// err := runJobNotify(req, client) if err != nil {
// if err != nil { log.Errorf("error executing notification step. %s", err)
// log.Errorf("error executing notification step. %s", err) }
// }
// break
// }
} }
func newDockerClient(addr, cert, key, ca string) (dockerclient.Client, error) { func newDockerClient(addr, cert, key, ca string) (dockerclient.Client, error) {
@ -290,7 +287,7 @@ func runJob(r *Task, updater *updater, client dockerclient.Client) error {
}, },
} }
// w.client.PullImage(conf.Image, nil) client.PullImage(conf.Image, nil)
_, err = docker.RunDaemon(client, conf, name) _, err = docker.RunDaemon(client, conf, name)
if err != nil { if err != nil {
@ -384,9 +381,30 @@ func runJobNotify(r *Task, client dockerclient.Client) error {
Image: DefaultAgent, Image: DefaultAgent,
Entrypoint: DefaultEntrypoint, Entrypoint: DefaultEntrypoint,
Cmd: args, Cmd: args,
HostConfig: dockerclient.HostConfig{}, HostConfig: dockerclient.HostConfig{
Binds: []string{"/var/run/docker.sock:/var/run/docker.sock"},
},
Volumes: map[string]struct{}{
"/var/run/docker.sock": struct{}{},
},
}
info, err := docker.Run(client, conf, name)
// for debugging purposes we print a failed notification executions
// output to the logs. Otherwise we have no way to troubleshoot failed
// notifications. This is temporary code until I've come up with
// a better solution.
if info != nil && info.State.ExitCode != 0 && log.GetLevel() >= log.InfoLevel {
var buf bytes.Buffer
rc, err := client.ContainerLogs(name, docker.LogOpts)
if err == nil {
defer rc.Close()
stdcopy.StdCopy(&buf, &buf, io.LimitReader(rc, 50000))
}
log.Infof("Notification container %s exited with %d", name, info.State.ExitCode)
log.Infoln(buf.String())
} }
_, err = docker.Run(client, conf, name)
return err return err
} }

View File

@ -14,7 +14,7 @@ type Task struct {
Repo *model.Repo `json:"repo"` Repo *model.Repo `json:"repo"`
Build *model.Build `json:"build"` Build *model.Build `json:"build"`
BuildPrev *model.Build `json:"build_last"` BuildPrev *model.Build `json:"build_last"`
Jobs []*model.Job `json:"jobs"` Jobs []*model.Job `json:"-"`
Job *model.Job `json:"job"` Job *model.Job `json:"job"`
Keys *model.Key `json:"keys"` Keys *model.Key `json:"keys"`
Netrc *model.Netrc `json:"netrc"` Netrc *model.Netrc `json:"netrc"`

View File

@ -5,31 +5,31 @@ import (
) )
func encodeToLegacyFormat(t *Task) ([]byte, error) { func encodeToLegacyFormat(t *Task) ([]byte, error) {
t.System.Plugins = append(t.System.Plugins, "plugins/*") // t.System.Plugins = append(t.System.Plugins, "plugins/*")
s := map[string]interface{}{} // s := map[string]interface{}{}
s["repo"] = t.Repo // s["repo"] = t.Repo
s["config"] = t.Config // s["config"] = t.Config
s["secret"] = t.Secret // s["secret"] = t.Secret
s["job"] = t.Job // s["job"] = t.Job
s["system"] = t.System // s["system"] = t.System
s["workspace"] = map[string]interface{}{ // s["workspace"] = map[string]interface{}{
"netrc": t.Netrc, // "netrc": t.Netrc,
"keys": t.Keys, // "keys": t.Keys,
} // }
s["build"] = map[string]interface{}{ // s["build"] = map[string]interface{}{
"number": t.Build.Number, // "number": t.Build.Number,
"status": t.Build.Status, // "status": t.Build.Status,
"head_commit": map[string]interface{}{ // "head_commit": map[string]interface{}{
"sha": t.Build.Commit, // "sha": t.Build.Commit,
"ref": t.Build.Ref, // "ref": t.Build.Ref,
"branch": t.Build.Branch, // "branch": t.Build.Branch,
"message": t.Build.Message, // "message": t.Build.Message,
"author": map[string]interface{}{ // "author": map[string]interface{}{
"login": t.Build.Author, // "login": t.Build.Author,
"email": t.Build.Email, // "email": t.Build.Email,
}, // },
}, // },
} // }
return json.Marshal(&s) return json.Marshal(t)
} }

View File

@ -15,10 +15,10 @@ var (
DefaultEntrypoint = []string{"/bin/drone-exec"} DefaultEntrypoint = []string{"/bin/drone-exec"}
// default argument to invoke build steps // default argument to invoke build steps
DefaultBuildArgs = []string{"--pull", "--cache", "--debug", "--clone", "--build", "--deploy"} DefaultBuildArgs = []string{"--pull", "--cache", "--clone", "--build", "--deploy"}
// default argument to invoke build steps // default argument to invoke build steps
DefaultPullRequestArgs = []string{"--cache", "--clone", "--build"} DefaultPullRequestArgs = []string{"--pull", "--cache", "--clone", "--build"}
// default arguments to invoke notify steps // default arguments to invoke notify steps
DefaultNotifyArgs = []string{"--pull", "--notify"} DefaultNotifyArgs = []string{"--pull", "--notify"}