diff --git a/drone.go b/drone.go index f9a2f9d2f..a30e8df60 100644 --- a/drone.go +++ b/drone.go @@ -16,7 +16,7 @@ import ( var ( dotenv = flag.String("config", ".env", "") - debug = flag.Bool("debug", true, "") + debug = flag.Bool("debug", false, "") ) func main() { diff --git a/engine/engine.go b/engine/engine.go index dbc95f3e7..67b1ee8f8 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -140,7 +140,7 @@ func (e *engine) Schedule(req *Task) { const size = 64 << 10 buf := make([]byte, size) 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) }() @@ -177,7 +177,7 @@ func (e *engine) Schedule(req *Task) { runJob(req, e.updater, client) } - // TODO + // update overall status based on each job req.Build.Status = model.StatusSuccess for _, job := range req.Jobs { if job.Status != model.StatusSuccess { @@ -191,14 +191,11 @@ func (e *engine) Schedule(req *Task) { log.Errorf("error updating build completion status. %s", err) } - // run notifications!!! - // for _ = range req.Jobs { - // err := runJobNotify(req, client) - // if err != nil { - // log.Errorf("error executing notification step. %s", err) - // } - // break - // } + // run notifications + err = runJobNotify(req, client) + if err != nil { + log.Errorf("error executing notification step. %s", err) + } } 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) if err != nil { @@ -384,9 +381,30 @@ func runJobNotify(r *Task, client dockerclient.Client) error { Image: DefaultAgent, Entrypoint: DefaultEntrypoint, 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 } diff --git a/engine/types.go b/engine/types.go index 27cf6ec75..8ba2dd3c3 100644 --- a/engine/types.go +++ b/engine/types.go @@ -14,7 +14,7 @@ type Task struct { Repo *model.Repo `json:"repo"` Build *model.Build `json:"build"` BuildPrev *model.Build `json:"build_last"` - Jobs []*model.Job `json:"jobs"` + Jobs []*model.Job `json:"-"` Job *model.Job `json:"job"` Keys *model.Key `json:"keys"` Netrc *model.Netrc `json:"netrc"` diff --git a/engine/util.go b/engine/util.go index db195754a..b8f9068bd 100644 --- a/engine/util.go +++ b/engine/util.go @@ -5,31 +5,31 @@ import ( ) 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["repo"] = t.Repo - s["config"] = t.Config - s["secret"] = t.Secret - s["job"] = t.Job - s["system"] = t.System - s["workspace"] = map[string]interface{}{ - "netrc": t.Netrc, - "keys": t.Keys, - } - s["build"] = map[string]interface{}{ - "number": t.Build.Number, - "status": t.Build.Status, - "head_commit": map[string]interface{}{ - "sha": t.Build.Commit, - "ref": t.Build.Ref, - "branch": t.Build.Branch, - "message": t.Build.Message, - "author": map[string]interface{}{ - "login": t.Build.Author, - "email": t.Build.Email, - }, - }, - } - return json.Marshal(&s) + // s := map[string]interface{}{} + // s["repo"] = t.Repo + // s["config"] = t.Config + // s["secret"] = t.Secret + // s["job"] = t.Job + // s["system"] = t.System + // s["workspace"] = map[string]interface{}{ + // "netrc": t.Netrc, + // "keys": t.Keys, + // } + // s["build"] = map[string]interface{}{ + // "number": t.Build.Number, + // "status": t.Build.Status, + // "head_commit": map[string]interface{}{ + // "sha": t.Build.Commit, + // "ref": t.Build.Ref, + // "branch": t.Build.Branch, + // "message": t.Build.Message, + // "author": map[string]interface{}{ + // "login": t.Build.Author, + // "email": t.Build.Email, + // }, + // }, + // } + return json.Marshal(t) } diff --git a/engine/worker.go b/engine/worker.go index 7cc61a558..3d535d775 100644 --- a/engine/worker.go +++ b/engine/worker.go @@ -15,10 +15,10 @@ var ( DefaultEntrypoint = []string{"/bin/drone-exec"} // 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 - DefaultPullRequestArgs = []string{"--cache", "--clone", "--build"} + DefaultPullRequestArgs = []string{"--pull", "--cache", "--clone", "--build"} // default arguments to invoke notify steps DefaultNotifyArgs = []string{"--pull", "--notify"}