got the build working correctly
This commit is contained in:
parent
7abe695a5c
commit
aec9b33048
7 changed files with 39 additions and 15 deletions
|
@ -1,7 +1,6 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/drone/drone/server/queue"
|
||||
|
@ -49,6 +48,8 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
//fmt.Printf("%#v", hook)
|
||||
|
||||
// fetch the repository from the database
|
||||
repo, err := h.repos.FindName(remote.GetHost(), hook.Owner, hook.Repo)
|
||||
if err != nil {
|
||||
|
@ -90,8 +91,7 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error {
|
|||
return badRequest{err}
|
||||
}
|
||||
|
||||
fmt.Printf("%#v", hook)
|
||||
fmt.Printf("%s", yml)
|
||||
//fmt.Printf("%s", yml)
|
||||
|
||||
// drop the items on the queue
|
||||
h.queue.Add(&queue.BuildTask{Repo: repo, Commit: &c})
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/drone/drone/server/resource/user"
|
||||
"github.com/drone/drone/server/session"
|
||||
"github.com/drone/drone/shared/build/docker"
|
||||
"github.com/drone/drone/shared/build/log"
|
||||
|
||||
"github.com/gorilla/pat"
|
||||
//"github.com/justinas/nosurf"
|
||||
|
@ -63,6 +64,8 @@ var conf config.Config
|
|||
|
||||
func main() {
|
||||
|
||||
log.SetPriority(log.LOG_NOTICE)
|
||||
|
||||
// parse command line flags
|
||||
flag.StringVar(&port, "port", ":8080", "")
|
||||
flag.StringVar(&driver, "driver", "sqlite3", "")
|
||||
|
@ -92,10 +95,6 @@ func main() {
|
|||
db, _ := sql.Open(driver, datasource)
|
||||
database.Load(db)
|
||||
|
||||
// setup the build queue
|
||||
queueRunner := queue.NewBuildRunner(docker.New(), timeout)
|
||||
queue := queue.Start(workers, queueRunner)
|
||||
|
||||
// setup the database managers
|
||||
repos := repo.NewManager(db)
|
||||
users := user.NewManager(db)
|
||||
|
@ -105,6 +104,10 @@ func main() {
|
|||
// cancel all previously running builds
|
||||
go commits.CancelAll()
|
||||
|
||||
// setup the build queue
|
||||
queueRunner := queue.NewBuildRunner(docker.New(), timeout)
|
||||
queue := queue.Start(workers, commits, queueRunner)
|
||||
|
||||
// setup the session managers
|
||||
sess := session.NewSession(users)
|
||||
|
||||
|
|
|
@ -26,13 +26,14 @@ type BuildTask struct {
|
|||
}
|
||||
|
||||
// Start N workers with the given build runner.
|
||||
func Start(workers int, runner BuildRunner) *Queue {
|
||||
func Start(workers int, commits commit.CommitManager, runner BuildRunner) *Queue {
|
||||
tasks := make(chan *BuildTask)
|
||||
queue := &Queue{tasks: tasks}
|
||||
|
||||
for i := 0; i < workers; i++ {
|
||||
worker := worker{
|
||||
runner: runner,
|
||||
runner: runner,
|
||||
commits: commits,
|
||||
}
|
||||
|
||||
go worker.work(tasks)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
r "github.com/drone/drone/shared/build/repo"
|
||||
"github.com/drone/drone/shared/build/script"
|
||||
"io"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
|
@ -34,7 +35,10 @@ func (w *worker) work(queue <-chan *BuildTask) {
|
|||
}
|
||||
|
||||
// execute the task
|
||||
w.execute(task)
|
||||
err := w.execute(task)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,6 +61,7 @@ func (w *worker) execute(task *BuildTask) error {
|
|||
params, err := task.Repo.ParamMap()
|
||||
task.Script, err = script.ParseBuild(task.Commit.Config, params)
|
||||
if err != nil {
|
||||
log.Printf("Error parsing repository params. %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -66,6 +71,7 @@ func (w *worker) execute(task *BuildTask) error {
|
|||
|
||||
// persist the commit to the database
|
||||
if err := w.commits.Update(task.Commit); err != nil {
|
||||
log.Printf("Error updating commit. %s\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -166,7 +172,7 @@ func (w *worker) execute(task *BuildTask) error {
|
|||
func (w *worker) runBuild(task *BuildTask, buf io.Writer) (bool, error) {
|
||||
repo := &r.Repo{
|
||||
Name: task.Repo.Host + task.Repo.Owner + task.Repo.Name,
|
||||
Path: task.Repo.URL,
|
||||
Path: task.Repo.CloneURL,
|
||||
Branch: task.Commit.Branch,
|
||||
Commit: task.Commit.Sha,
|
||||
PR: task.Commit.PullRequest,
|
||||
|
@ -175,6 +181,10 @@ func (w *worker) runBuild(task *BuildTask, buf io.Writer) (bool, error) {
|
|||
Depth: git.GitDepth(task.Script.Git),
|
||||
}
|
||||
|
||||
if task.Repo.Private {
|
||||
repo.Path = task.Repo.SSHURL
|
||||
}
|
||||
|
||||
return w.runner.Run(
|
||||
task.Script,
|
||||
repo,
|
||||
|
|
|
@ -167,7 +167,7 @@ func (b *Builder) setup() error {
|
|||
src := filepath.Join(dir, "src")
|
||||
cmd := exec.Command("cp", "-a", b.Repo.Path, src)
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("Error: Unable to copy repository. %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ func (b *Buildfile) WriteHost(mapping string) {
|
|||
// code at the start.
|
||||
var base = `
|
||||
#!/bin/bash
|
||||
set +e
|
||||
|
||||
# drone configuration files are stored in /etc/drone.d
|
||||
# execute these files prior to our build to set global
|
||||
|
|
|
@ -81,6 +81,10 @@ func (g *Github) GetHook(r *http.Request) (*remote.Hook, error) {
|
|||
hook.Sha = data.Head.Id
|
||||
hook.Branch = data.Branch()
|
||||
|
||||
if len(hook.Owner) == 0 {
|
||||
hook.Owner = data.Repo.Owner.Name
|
||||
}
|
||||
|
||||
// extract the author and message from the commit
|
||||
// this is kind of experimental, since I don't know
|
||||
// what I'm doing here.
|
||||
|
@ -114,8 +118,7 @@ func (g *Github) GetPullRequestHook(r *http.Request) (*remote.Hook, error) {
|
|||
|
||||
// TODO we should also store the pull request branch (ie from x to y)
|
||||
// we can find it here: data.PullRequest.Head.Ref
|
||||
|
||||
return &remote.Hook{
|
||||
hook := remote.Hook{
|
||||
Owner: data.Repo.Owner.Login,
|
||||
Repo: data.Repo.Name,
|
||||
Sha: data.PullRequest.Head.Sha,
|
||||
|
@ -125,7 +128,13 @@ func (g *Github) GetPullRequestHook(r *http.Request) (*remote.Hook, error) {
|
|||
Timestamp: time.Now().UTC().String(),
|
||||
Message: data.PullRequest.Title,
|
||||
PullRequest: strconv.Itoa(data.Number),
|
||||
}, nil
|
||||
}
|
||||
|
||||
if len(hook.Owner) == 0 {
|
||||
hook.Owner = data.Repo.Owner.Name
|
||||
}
|
||||
|
||||
return &hook, nil
|
||||
}
|
||||
|
||||
// GetLogin handles authentication to third party, remote services
|
||||
|
|
Loading…
Reference in a new issue