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 (
dotenv = flag.String("config", ".env", "")
debug = flag.Bool("debug", true, "")
debug = flag.Bool("debug", false, "")
)
func main() {

View file

@ -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
}

View file

@ -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"`

View file

@ -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)
}

View file

@ -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"}