mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
initial queue code added. also ability to extract Hostname from remote
This commit is contained in:
parent
c7d63ec7ce
commit
d0dd308523
7 changed files with 69 additions and 6 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"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/config"
|
"github.com/drone/drone/server/resource/config"
|
||||||
"github.com/drone/drone/server/resource/repo"
|
"github.com/drone/drone/server/resource/repo"
|
||||||
|
@ -15,11 +16,12 @@ type HookHandler struct {
|
||||||
users user.UserManager
|
users user.UserManager
|
||||||
repos repo.RepoManager
|
repos repo.RepoManager
|
||||||
commits commit.CommitManager
|
commits commit.CommitManager
|
||||||
|
queue *queue.Queue
|
||||||
conf *config.Config
|
conf *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHookHandler(users user.UserManager, repos repo.RepoManager, commits commit.CommitManager, conf *config.Config) *HookHandler {
|
func NewHookHandler(users user.UserManager, repos repo.RepoManager, commits commit.CommitManager, conf *config.Config, queue *queue.Queue) *HookHandler {
|
||||||
return &HookHandler{users, repos, commits, conf}
|
return &HookHandler{users, repos, commits, queue, conf}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostHook receives a post-commit hook from GitHub, Bitbucket, etc
|
// PostHook receives a post-commit hook from GitHub, Bitbucket, etc
|
||||||
|
@ -48,7 +50,7 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch the repository from the database
|
// fetch the repository from the database
|
||||||
repo, err := h.repos.FindName(host, hook.Owner, hook.Repo)
|
repo, err := h.repos.FindName(remote.GetHost(), hook.Owner, hook.Repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return notFound{}
|
return notFound{}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +93,7 @@ func (h *HookHandler) PostHook(w http.ResponseWriter, r *http.Request) error {
|
||||||
fmt.Printf("%s", script)
|
fmt.Printf("%s", script)
|
||||||
|
|
||||||
// drop the items on the queue
|
// drop the items on the queue
|
||||||
//h.queue.Add(&queue.BuildTask{Repo: repo, Commit: commit, Build: build, Script: script})
|
//h.queue.Add(&queue.BuildTask{Repo: repo, Commit: &c, Script: script})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,14 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.google.com/p/go.net/websocket"
|
"code.google.com/p/go.net/websocket"
|
||||||
"github.com/drone/drone/server/channel"
|
"github.com/drone/drone/server/channel"
|
||||||
"github.com/drone/drone/server/database"
|
"github.com/drone/drone/server/database"
|
||||||
"github.com/drone/drone/server/handler"
|
"github.com/drone/drone/server/handler"
|
||||||
|
"github.com/drone/drone/server/queue"
|
||||||
"github.com/drone/drone/server/render"
|
"github.com/drone/drone/server/render"
|
||||||
"github.com/drone/drone/server/resource/commit"
|
"github.com/drone/drone/server/resource/commit"
|
||||||
"github.com/drone/drone/server/resource/config"
|
"github.com/drone/drone/server/resource/config"
|
||||||
|
@ -17,6 +20,7 @@ import (
|
||||||
"github.com/drone/drone/server/resource/repo"
|
"github.com/drone/drone/server/resource/repo"
|
||||||
"github.com/drone/drone/server/resource/user"
|
"github.com/drone/drone/server/resource/user"
|
||||||
"github.com/drone/drone/server/session"
|
"github.com/drone/drone/server/session"
|
||||||
|
"github.com/drone/drone/shared/build/docker"
|
||||||
|
|
||||||
"github.com/gorilla/pat"
|
"github.com/gorilla/pat"
|
||||||
//"github.com/justinas/nosurf"
|
//"github.com/justinas/nosurf"
|
||||||
|
@ -42,6 +46,14 @@ var (
|
||||||
// commit sha for the current build.
|
// commit sha for the current build.
|
||||||
version string = "0.2-dev"
|
version string = "0.2-dev"
|
||||||
revision string
|
revision string
|
||||||
|
|
||||||
|
// build will timeout after N milliseconds.
|
||||||
|
// this will default to 500 minutes (6 hours)
|
||||||
|
timeout time.Duration
|
||||||
|
|
||||||
|
// Number of concurrent build workers to run
|
||||||
|
// default to number of CPUs on machine
|
||||||
|
workers int
|
||||||
)
|
)
|
||||||
|
|
||||||
// drone cofiguration data, loaded from the
|
// drone cofiguration data, loaded from the
|
||||||
|
@ -56,6 +68,8 @@ func main() {
|
||||||
flag.StringVar(&datasource, "datasource", "drone.sqlite", "")
|
flag.StringVar(&datasource, "datasource", "drone.sqlite", "")
|
||||||
flag.StringVar(&sslcert, "sslcert", "", "")
|
flag.StringVar(&sslcert, "sslcert", "", "")
|
||||||
flag.StringVar(&sslkey, "sslkey", "", "")
|
flag.StringVar(&sslkey, "sslkey", "", "")
|
||||||
|
flag.DurationVar(&timeout, "timeout", 300*time.Minute, "")
|
||||||
|
flag.IntVar(&workers, "workers", runtime.NumCPU(), "")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// parse the template files
|
// parse the template files
|
||||||
|
@ -69,6 +83,10 @@ func main() {
|
||||||
db, _ := sql.Open(driver, datasource)
|
db, _ := sql.Open(driver, datasource)
|
||||||
database.Load(db)
|
database.Load(db)
|
||||||
|
|
||||||
|
// setup the build queue
|
||||||
|
queueRunner := queue.NewBuildRunner(docker.New(), timeout)
|
||||||
|
queue := queue.Start(workers, queueRunner)
|
||||||
|
|
||||||
// setup the database managers
|
// setup the database managers
|
||||||
repos := repo.NewManager(db)
|
repos := repo.NewManager(db)
|
||||||
users := user.NewManager(db)
|
users := user.NewManager(db)
|
||||||
|
@ -82,7 +100,7 @@ func main() {
|
||||||
router := pat.New()
|
router := pat.New()
|
||||||
handler.NewUsersHandler(users, sess).Register(router)
|
handler.NewUsersHandler(users, sess).Register(router)
|
||||||
handler.NewUserHandler(users, repos, commits, sess).Register(router)
|
handler.NewUserHandler(users, repos, commits, sess).Register(router)
|
||||||
handler.NewHookHandler(users, repos, commits, &conf).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).Register(router)
|
||||||
handler.NewBranchHandler(repos, commits, perms, sess).Register(router)
|
handler.NewBranchHandler(repos, commits, perms, sess).Register(router)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package bitbucket
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/drone/drone/shared/remote"
|
"github.com/drone/drone/shared/remote"
|
||||||
|
@ -24,6 +25,15 @@ func (b *Bitbucket) GetName() string {
|
||||||
return "bitbucket.org"
|
return "bitbucket.org"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHost returns the url.Host of this remote system.
|
||||||
|
func (b *Bitbucket) GetHost() (host string) {
|
||||||
|
u, err := url.Parse(b.URL)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return u.Host
|
||||||
|
}
|
||||||
|
|
||||||
// GetHook parses the post-commit hook from the Request body
|
// GetHook parses the post-commit hook from the Request body
|
||||||
// and returns the required data in a standard format.
|
// and returns the required data in a standard format.
|
||||||
func (b *Bitbucket) GetHook(r *http.Request) (*remote.Hook, error) {
|
func (b *Bitbucket) GetHook(r *http.Request) (*remote.Hook, error) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package github
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -36,6 +37,15 @@ func (g *Github) GetName() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHost returns the url.Host of this remote system.
|
||||||
|
func (g *Github) GetHost() (host string) {
|
||||||
|
u, err := url.Parse(g.URL)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return u.Host
|
||||||
|
}
|
||||||
|
|
||||||
// GetHook parses the post-commit hook from the Request body
|
// GetHook parses the post-commit hook from the Request body
|
||||||
// and returns the required data in a standard format.
|
// and returns the required data in a standard format.
|
||||||
func (g *Github) GetHook(r *http.Request) (*remote.Hook, error) {
|
func (g *Github) GetHook(r *http.Request) (*remote.Hook, error) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package gitlab
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/drone/drone/shared/remote"
|
"github.com/drone/drone/shared/remote"
|
||||||
|
@ -17,6 +18,15 @@ func (g *Gitlab) GetName() string {
|
||||||
return "gitlab.com"
|
return "gitlab.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHost returns the url.Host of this remote system.
|
||||||
|
func (g *Gitlab) GetHost() (host string) {
|
||||||
|
u, err := url.Parse(g.URL)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return u.Host
|
||||||
|
}
|
||||||
|
|
||||||
// GetHook parses the post-commit hook from the Request body
|
// GetHook parses the post-commit hook from the Request body
|
||||||
// and returns the required data in a standard format.
|
// and returns the required data in a standard format.
|
||||||
func (g *Gitlab) GetHook(*http.Request) (*remote.Hook, error) {
|
func (g *Gitlab) GetHook(*http.Request) (*remote.Hook, error) {
|
||||||
|
|
|
@ -5,9 +5,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Remote interface {
|
type Remote interface {
|
||||||
// Name returns the name of this remote system.
|
// GetName returns the name of this remote system.
|
||||||
GetName() string
|
GetName() string
|
||||||
|
|
||||||
|
// GetHost returns the URL hostname of this remote system.
|
||||||
|
GetHost() (host string)
|
||||||
|
|
||||||
// GetHook parses the post-commit hook from the Request body
|
// GetHook parses the post-commit hook from the Request body
|
||||||
// and returns the required data in a standard format.
|
// and returns the required data in a standard format.
|
||||||
GetHook(*http.Request) (*Hook, error)
|
GetHook(*http.Request) (*Hook, error)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package stash
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/drone/drone/shared/remote"
|
"github.com/drone/drone/shared/remote"
|
||||||
|
@ -20,6 +21,15 @@ func (s *Stash) GetName() string {
|
||||||
return "stash.atlassian.com"
|
return "stash.atlassian.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHost returns the url.Host of this remote system.
|
||||||
|
func (s *Stash) GetHost() (host string) {
|
||||||
|
u, err := url.Parse(s.URL)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return u.Host
|
||||||
|
}
|
||||||
|
|
||||||
// GetHook parses the post-commit hook from the Request body
|
// GetHook parses the post-commit hook from the Request body
|
||||||
// and returns the required data in a standard format.
|
// and returns the required data in a standard format.
|
||||||
func (s *Stash) GetHook(*http.Request) (*remote.Hook, error) {
|
func (s *Stash) GetHook(*http.Request) (*remote.Hook, error) {
|
||||||
|
|
Loading…
Reference in a new issue