Skip to content

Commit

Permalink
updating for latest data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Sep 30, 2015
1 parent 9790f1a commit aa320db
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 43 deletions.
2 changes: 1 addition & 1 deletion drone.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var (
dotenv = flag.String("config", ".env", "")
debug = flag.Bool("debug", true, "")
debug = flag.Bool("debug", false, "")
)

func main() {
Expand Down
44 changes: 31 additions & 13 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}()
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion engine/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
52 changes: 26 additions & 26 deletions engine/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions engine/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down

0 comments on commit aa320db

Please sign in to comment.