2015-09-30 01:21:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-04-11 22:49:10 +00:00
|
|
|
"net/http"
|
2016-04-11 22:55:13 +00:00
|
|
|
"time"
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
"github.com/drone/drone/engine"
|
|
|
|
"github.com/drone/drone/remote"
|
|
|
|
"github.com/drone/drone/router"
|
2015-10-20 23:45:24 +00:00
|
|
|
"github.com/drone/drone/router/middleware/cache"
|
2015-09-30 01:21:17 +00:00
|
|
|
"github.com/drone/drone/router/middleware/context"
|
2015-10-13 09:08:08 +00:00
|
|
|
"github.com/drone/drone/router/middleware/header"
|
2015-09-30 01:21:17 +00:00
|
|
|
"github.com/drone/drone/shared/envconfig"
|
2015-10-21 23:14:02 +00:00
|
|
|
"github.com/drone/drone/store/datastore"
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2016-04-11 22:55:13 +00:00
|
|
|
"github.com/gin-gonic/contrib/ginrus"
|
2016-04-11 22:49:10 +00:00
|
|
|
"github.com/ianschenck/envflag"
|
|
|
|
_ "github.com/joho/godotenv/autoload"
|
2015-09-30 01:21:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2016-04-11 22:49:10 +00:00
|
|
|
addr = envflag.String("SERVER_ADDR", ":8000", "")
|
|
|
|
cert = envflag.String("SERVER_CERT", "", "")
|
|
|
|
key = envflag.String("SERVER_KEY", "", "")
|
|
|
|
|
|
|
|
debug = envflag.Bool("DEBUG", false, "")
|
2015-09-30 01:21:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-04-11 22:49:10 +00:00
|
|
|
envflag.Parse()
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
// debug level if requested by user
|
|
|
|
if *debug {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the configuration from env file
|
2016-04-11 22:49:10 +00:00
|
|
|
env := envconfig.Load(".env")
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
// Setup the database driver
|
2015-10-21 23:14:02 +00:00
|
|
|
store_ := datastore.Load(env)
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
// setup the remote driver
|
|
|
|
remote_ := remote.Load(env)
|
|
|
|
|
|
|
|
// setup the runner
|
2015-10-21 23:14:02 +00:00
|
|
|
engine_ := engine.Load(env, store_)
|
2015-09-30 01:21:17 +00:00
|
|
|
|
|
|
|
// setup the server and start the listener
|
2016-04-11 22:49:10 +00:00
|
|
|
handler := router.Load(
|
2016-04-11 22:55:13 +00:00
|
|
|
ginrus.Ginrus(logrus.StandardLogger(), time.RFC3339, true),
|
2016-04-11 22:49:10 +00:00
|
|
|
header.Version,
|
|
|
|
cache.Default(),
|
|
|
|
context.SetStore(store_),
|
|
|
|
context.SetRemote(remote_),
|
|
|
|
context.SetEngine(engine_),
|
2015-09-30 01:21:17 +00:00
|
|
|
)
|
2016-04-11 22:49:10 +00:00
|
|
|
|
|
|
|
if *cert != "" {
|
|
|
|
logrus.Fatal(
|
|
|
|
http.ListenAndServeTLS(*addr, *cert, *key, handler),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
logrus.Fatal(
|
|
|
|
http.ListenAndServe(*addr, handler),
|
|
|
|
)
|
|
|
|
}
|
2015-09-30 01:21:17 +00:00
|
|
|
}
|