hooked the build queue back up

This commit is contained in:
Brad 2014-06-11 17:42:49 -07:00
parent 30b38bd4b7
commit 7abe695a5c
10 changed files with 111 additions and 49 deletions

View file

@ -12,12 +12,12 @@ notify:
recipients: recipients:
- brad@drone.io - brad@drone.io
publish: #publish:
s3: # s3:
acl: public-read # acl: public-read
region: us-east-1 # region: us-east-1
bucket: downloads.drone.io # bucket: downloads.drone.io
access_key: $AWS_KEY # access_key: $AWS_KEY
secret_key: $AWS_SECRET # secret_key: $AWS_SECRET
source: deb/drone.deb # source: deb/drone.deb
target: exp/ # target: exp/

View file

@ -1,6 +1,6 @@
SHA := $(shell git rev-parse --short HEAD) SHA := $(shell git rev-parse --short HEAD)
all: build all: rice amberc lessc build
deps: deps:
go list github.com/drone/drone/... | xargs go get -t go list github.com/drone/drone/... | xargs go get -t
@ -23,6 +23,10 @@ clean:
#cd cmd/droned/static && rice clean #cd cmd/droned/static && rice clean
#cd cmd/droned/template && rice clean #cd cmd/droned/template && rice clean
rice:
cd server && rice embed
#cd server/template/html && rice embed
amberc: amberc:
@for f in server/template/*.amber; do $$GOPATH/bin/amberc -pp=true "$$f" > "$${f%.amber}.html"; done @for f in server/template/*.amber; do $$GOPATH/bin/amberc -pp=true "$$f" > "$${f%.amber}.html"; done
@mkdir -p server/template/html @mkdir -p server/template/html
@ -40,9 +44,9 @@ uglify:
# creates a debian package for drone # creates a debian package for drone
# to install `sudo dpkg -i drone.deb` # to install `sudo dpkg -i drone.deb`
dpkg: build dpkg:
mkdir -p debian/drone/usr/local/bin mkdir -p debian/drone/usr/local/bin
-dpkg-deb --build debian/drone -dpkg-deb --build debian/drone
run: run:
@cd server && go run main.go conf.go @cd server && go run main.go conf.gomake

View file

@ -1,6 +1,6 @@
start on (filesystem and net-device-up) start on (filesystem and net-device-up)
chdir /var/lib/drone chdir /root/.drone
console log console log
script script

View file

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"github.com/drone/drone/server/queue"
"github.com/drone/drone/server/resource/commit" "github.com/drone/drone/server/resource/commit"
"github.com/drone/drone/server/resource/perm" "github.com/drone/drone/server/resource/perm"
"github.com/drone/drone/server/resource/repo" "github.com/drone/drone/server/resource/repo"
@ -16,10 +17,11 @@ type CommitHandler struct {
repos repo.RepoManager repos repo.RepoManager
commits commit.CommitManager commits commit.CommitManager
sess session.Session sess session.Session
queue *queue.Queue
} }
func NewCommitHandler(repos repo.RepoManager, commits commit.CommitManager, perms perm.PermManager, sess session.Session) *CommitHandler { func NewCommitHandler(repos repo.RepoManager, commits commit.CommitManager, perms perm.PermManager, sess session.Session, queue *queue.Queue) *CommitHandler {
return &CommitHandler{perms, repos, commits, sess} return &CommitHandler{perms, repos, commits, sess, queue}
} }
// GetFeed gets recent commits for the repository and branch // GetFeed gets recent commits for the repository and branch
@ -117,6 +119,49 @@ func (h *CommitHandler) GetCommitOutput(w http.ResponseWriter, r *http.Request)
// PostCommit gets the commit for the repository and schedules to re-build. // PostCommit gets the commit for the repository and schedules to re-build.
// GET /v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit} // GET /v1/repos/{host}/{owner}/{name}/branches/{branch}/commits/{commit}
func (h *CommitHandler) PostCommit(w http.ResponseWriter, r *http.Request) error { func (h *CommitHandler) PostCommit(w http.ResponseWriter, r *http.Request) error {
var host, owner, name = parseRepo(r)
var branch = r.FormValue(":branch")
var sha = r.FormValue(":commit")
// get the user form the session.
user := h.sess.User(r)
if user == nil {
return notAuthorized{}
}
// get the repo from the database
repo, err := h.repos.FindName(host, owner, name)
if err != nil {
return notFound{err}
}
// user must have admin access to the repository.
if ok, _ := h.perms.Admin(user, repo); !ok {
return notFound{err}
}
c, err := h.commits.FindSha(repo.ID, branch, sha)
if err != nil {
return notFound{err}
}
// we can't start an already started build
if c.Status == commit.StatusStarted || c.Status == commit.StatusEnqueue {
return badRequest{}
}
c.Status = commit.StatusEnqueue
c.Started = 0
c.Finished = 0
c.Duration = 0
if err := h.commits.Update(c); err != nil {
return internalServerError{err}
}
// drop the items on the queue
h.queue.Add(&queue.BuildTask{Repo: repo, Commit: c})
return nil
return notImplemented{} return notImplemented{}
} }

View file

@ -70,7 +70,7 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error {
// featch the .drone.yml file from the database // featch the .drone.yml file from the database
client := remote.GetClient(user.Access, user.Secret) client := remote.GetClient(user.Access, user.Secret)
script, err := client.GetScript(hook) yml, err := client.GetScript(hook)
if err != nil { if err != nil {
return badRequest{err} return badRequest{err}
} }
@ -82,7 +82,8 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error {
Branch: hook.Branch, Branch: hook.Branch,
PullRequest: hook.PullRequest, PullRequest: hook.PullRequest,
Timestamp: hook.Timestamp, Timestamp: hook.Timestamp,
Message: hook.Message} Message: hook.Message,
Config: yml}
c.SetAuthor(hook.Author) c.SetAuthor(hook.Author)
// inser the commit into the database // inser the commit into the database
if err := h.commits.Insert(&c); err != nil { if err := h.commits.Insert(&c); err != nil {
@ -90,10 +91,10 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error {
} }
fmt.Printf("%#v", hook) fmt.Printf("%#v", hook)
fmt.Printf("%s", script) fmt.Printf("%s", yml)
// drop the items on the queue // drop the items on the queue
//h.queue.Add(&queue.BuildTask{Repo: repo, Commit: &c, Script: script}) h.queue.Add(&queue.BuildTask{Repo: repo, Commit: &c})
return nil return nil
} }

View file

@ -24,6 +24,7 @@ import (
"github.com/gorilla/pat" "github.com/gorilla/pat"
//"github.com/justinas/nosurf" //"github.com/justinas/nosurf"
"github.com/GeertJohan/go.rice"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"github.com/russross/meddler" "github.com/russross/meddler"
) )
@ -74,9 +75,17 @@ func main() {
// parse the template files // parse the template files
// TODO we need to retrieve these from go.rice // TODO we need to retrieve these from go.rice
templ := template.Must( //templ := template.Must(
template.New("_").Funcs(render.FuncMap).ParseGlob("template/html/*.html"), // template.New("_").Funcs(render.FuncMap).ParseGlob("template/html/*.html"),
).ExecuteTemplate //).ExecuteTemplate
templateBox := rice.MustFindBox("template/html")
templateFiles := []string{"login.html", "repo_branch.html", "repo_commit.html", "repo_conf.html", "repo_feed.html", "user_conf.html", "user_feed.html", "user_login.html", "user_repos.html", "404.html", "400.html"}
templ := template.New("_").Funcs(render.FuncMap)
for _, file := range templateFiles {
templateData, _ := templateBox.String(file)
templ, _ = templ.New(file).Parse(templateData)
}
// setup the database // setup the database
meddler.Default = meddler.SQLite meddler.Default = meddler.SQLite
@ -105,16 +114,16 @@ func main() {
handler.NewUserHandler(users, repos, commits, sess).Register(router) handler.NewUserHandler(users, repos, commits, sess).Register(router)
handler.NewHookHandler(users, repos, commits, &conf, queue).Register(router) handler.NewHookHandler(users, repos, commits, &conf, queue).Register(router)
handler.NewLoginHandler(users, repos, perms, sess, &conf).Register(router) handler.NewLoginHandler(users, repos, perms, sess, &conf).Register(router)
handler.NewCommitHandler(repos, commits, perms, sess).Register(router) handler.NewCommitHandler(repos, commits, perms, sess, queue).Register(router)
handler.NewBranchHandler(repos, commits, perms, sess).Register(router) handler.NewBranchHandler(repos, commits, perms, sess).Register(router)
handler.NewRepoHandler(repos, commits, perms, sess, &conf).Register(router) handler.NewRepoHandler(repos, commits, perms, sess, &conf).Register(router)
handler.NewBadgeHandler(repos, commits).Register(router) handler.NewBadgeHandler(repos, commits).Register(router)
handler.NewConfigHandler(conf, sess).Register(router) handler.NewConfigHandler(conf, sess).Register(router)
handler.NewSiteHandler(users, repos, commits, perms, sess, templ).Register(router) handler.NewSiteHandler(users, repos, commits, perms, sess, templ.ExecuteTemplate).Register(router)
// serve static assets // serve static assets
// TODO we need to replace this with go.rice // TODO we need to replace this with go.rice
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(rice.MustFindBox("static/").HTTPBox())))
// server websocket data // server websocket data
http.Handle("/feed", websocket.Handler(channel.Read)) http.Handle("/feed", websocket.Handler(channel.Read))

View file

@ -6,7 +6,7 @@ import (
"github.com/drone/drone/server/channel" "github.com/drone/drone/server/channel"
"github.com/drone/drone/shared/build/git" "github.com/drone/drone/shared/build/git"
r "github.com/drone/drone/shared/build/repo" r "github.com/drone/drone/shared/build/repo"
//"github.com/drone/drone/pkg/plugin/notify" "github.com/drone/drone/shared/build/script"
"io" "io"
"path/filepath" "path/filepath"
"time" "time"
@ -53,6 +53,13 @@ func (w *worker) execute(task *BuildTask) error {
} }
}() }()
// parse the build script
params, err := task.Repo.ParamMap()
task.Script, err = script.ParseBuild(task.Commit.Config, params)
if err != nil {
return err
}
// update commit and build status // update commit and build status
task.Commit.Status = commit.StatusStarted task.Commit.Status = commit.StatusStarted
task.Commit.Started = time.Now().Unix() task.Commit.Started = time.Now().Unix()

View file

@ -1,9 +1,15 @@
package repo package repo
var DefaultBranch = "master" import (
"gopkg.in/yaml.v1"
)
// default build timeout, in seconds var (
var DefaultTimeout int64 = 7200 DefaultBranch = "master"
// default build timeout, in seconds
DefaultTimeout int64 = 7200
)
const ( const (
HostGitlab = "gitlab.com" HostGitlab = "gitlab.com"
@ -65,3 +71,9 @@ func New(remote, owner, name string) (*Repo, error) {
repo.Timeout = DefaultTimeout repo.Timeout = DefaultTimeout
return &repo, nil return &repo, nil
} }
func (r *Repo) ParamMap() (map[string]string, error) {
out := map[string]string{}
err := yaml.Unmarshal([]byte(r.Params), out)
return out, err
}

View file

@ -3317,22 +3317,6 @@ article.pure-g > .pure-u-3-4 {
border: 1px solid #FEF0B8; border: 1px solid #FEF0B8;
padding-bottom: 40px; padding-bottom: 40px;
position: relative; position: relative;
/* not sure if this makes sense here
&:before {
text-transform: uppercase;
content: attr(data-status);
position: absolute;
top: 0px;
right: 0px;
font-family: 'Open Sans';
font-size:14px;
letter-spacing: 0;
background: #fef9e5;
color: #CBB45B;
padding: 5px 10px;
margin:0px;
}
*/
} }
.commit-item[data-status="Started"]:after, .commit-item[data-status="Started"]:after,
.commit-item[data-status="Pending"]:after { .commit-item[data-status="Pending"]:after {

View file

@ -6,7 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"strings" "strings"
"launchpad.net/goyaml" "gopkg.in/yaml.v1"
"github.com/drone/drone/shared/build/buildfile" "github.com/drone/drone/shared/build/buildfile"
"github.com/drone/drone/shared/build/git" "github.com/drone/drone/shared/build/git"
@ -16,11 +16,11 @@ import (
"github.com/drone/drone/shared/publish" "github.com/drone/drone/shared/publish"
) )
func ParseBuild(data []byte, params map[string]string) (*Build, error) { func ParseBuild(data string, params map[string]string) (*Build, error) {
build := Build{} build := Build{}
// parse the build configuration file // parse the build configuration file
err := goyaml.Unmarshal(injectParams(data, params), &build) err := yaml.Unmarshal(injectParams([]byte(data), params), &build)
return &build, err return &build, err
} }
@ -30,7 +30,7 @@ func ParseBuildFile(filename string) (*Build, error) {
return nil, err return nil, err
} }
return ParseBuild(data, nil) return ParseBuild(string(data), nil)
} }
// injectParams injects params into data. // injectParams injects params into data.