From cc93df0370332cce34e96585f889010683021a20 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 11 Apr 2016 15:49:10 -0700 Subject: [PATCH] removed server package --- Dockerfile.env | 10 ---------- drone.go | 41 ++++++++++++++++++++++++++--------------- shared/server/server.go | 36 ------------------------------------ 3 files changed, 26 insertions(+), 61 deletions(-) delete mode 100644 Dockerfile.env delete mode 100644 shared/server/server.go diff --git a/Dockerfile.env b/Dockerfile.env deleted file mode 100644 index d409b603..00000000 --- a/Dockerfile.env +++ /dev/null @@ -1,10 +0,0 @@ -# build environment used in .drone.yml -# -# docker build --rm=true -t drone/golang:1.5 -f Dockerfile.env . - -FROM golang:1.5 -ADD contrib/*.sh /usr/local/bin/ -RUN chmod +x /usr/local/bin/setup-sassc.sh && \ - chmod +x /usr/local/bin/setup-sqlite.sh && \ - /usr/local/bin/setup-sassc.sh && \ - /usr/local/bin/setup-sqlite.sh diff --git a/drone.go b/drone.go index c92281aa..bb5ade66 100644 --- a/drone.go +++ b/drone.go @@ -1,7 +1,7 @@ package main import ( - "flag" + "net/http" "github.com/drone/drone/engine" "github.com/drone/drone/remote" @@ -10,19 +10,23 @@ import ( "github.com/drone/drone/router/middleware/context" "github.com/drone/drone/router/middleware/header" "github.com/drone/drone/shared/envconfig" - "github.com/drone/drone/shared/server" "github.com/drone/drone/store/datastore" "github.com/Sirupsen/logrus" + "github.com/ianschenck/envflag" + _ "github.com/joho/godotenv/autoload" ) var ( - dotenv = flag.String("config", ".env", "") - debug = flag.Bool("debug", false, "") + addr = envflag.String("SERVER_ADDR", ":8000", "") + cert = envflag.String("SERVER_CERT", "", "") + key = envflag.String("SERVER_KEY", "", "") + + debug = envflag.Bool("DEBUG", false, "") ) func main() { - flag.Parse() + envflag.Parse() // debug level if requested by user if *debug { @@ -30,7 +34,7 @@ func main() { } // Load the configuration from env file - env := envconfig.Load(*dotenv) + env := envconfig.Load(".env") // Setup the database driver store_ := datastore.Load(env) @@ -42,14 +46,21 @@ func main() { engine_ := engine.Load(env, store_) // setup the server and start the listener - server_ := server.Load(env) - server_.Run( - router.Load( - header.Version, - cache.Default(), - context.SetStore(store_), - context.SetRemote(remote_), - context.SetEngine(engine_), - ), + handler := router.Load( + header.Version, + cache.Default(), + context.SetStore(store_), + context.SetRemote(remote_), + context.SetEngine(engine_), ) + + if *cert != "" { + logrus.Fatal( + http.ListenAndServeTLS(*addr, *cert, *key, handler), + ) + } else { + logrus.Fatal( + http.ListenAndServe(*addr, handler), + ) + } } diff --git a/shared/server/server.go b/shared/server/server.go deleted file mode 100644 index 9c3fafe8..00000000 --- a/shared/server/server.go +++ /dev/null @@ -1,36 +0,0 @@ -package server - -import ( - "net/http" - - log "github.com/Sirupsen/logrus" - "github.com/drone/drone/shared/envconfig" -) - -type Server struct { - Addr string - Cert string - Key string -} - -func Load(env envconfig.Env) *Server { - return &Server{ - Addr: env.String("SERVER_ADDR", ":8000"), - Cert: env.String("SERVER_CERT", ""), - Key: env.String("SERVER_KEY", ""), - } -} - -func (s *Server) Run(handler http.Handler) { - log.Infof("starting server %s", s.Addr) - - if len(s.Cert) != 0 { - log.Fatal( - http.ListenAndServeTLS(s.Addr, s.Cert, s.Key, handler), - ) - } else { - log.Fatal( - http.ListenAndServe(s.Addr, handler), - ) - } -}