mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-30 05:41:12 +00:00
hooked up SSL in exp branch
This commit is contained in:
parent
7a7c5a9c0d
commit
2080cd3309
2 changed files with 57 additions and 44 deletions
12
README.md
12
README.md
|
@ -54,6 +54,13 @@ The configuration file is in TOML format:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
|
|
||||||
|
[server]
|
||||||
|
port=""
|
||||||
|
|
||||||
|
[server.ssl]
|
||||||
|
key=""
|
||||||
|
cert=""
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
driver=""
|
driver=""
|
||||||
source=""
|
source=""
|
||||||
|
@ -98,6 +105,11 @@ Or you can use environment variables
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|
||||||
|
# custom database settings
|
||||||
|
export DRONE_SERVER_PORT=""
|
||||||
|
export DRONE_SERVER_SSL_KEY=""
|
||||||
|
export DRONE_SERVER_SSL_CERT=""
|
||||||
|
|
||||||
# custom database settings
|
# custom database settings
|
||||||
export DRONE_DATABASE_DRIVER=""
|
export DRONE_DATABASE_DRIVER=""
|
||||||
export DRONE_DATABASE_SOURCE=""
|
export DRONE_DATABASE_SOURCE=""
|
||||||
|
|
|
@ -33,37 +33,35 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// port the server will run on
|
// commit sha for the current build, set by
|
||||||
port string
|
// the compile process.
|
||||||
|
|
||||||
// database driver used to connect to the database
|
|
||||||
driver string
|
|
||||||
|
|
||||||
// driver specific connection information. In this
|
|
||||||
// case, it should be the location of the SQLite file
|
|
||||||
datasource string
|
|
||||||
|
|
||||||
// optional flags for tls listener
|
|
||||||
sslcert string
|
|
||||||
sslkey string
|
|
||||||
|
|
||||||
// commit sha for the current build.
|
|
||||||
version string = "0.3-dev"
|
version string = "0.3-dev"
|
||||||
revision string
|
revision string
|
||||||
|
)
|
||||||
|
|
||||||
conf string
|
var (
|
||||||
prefix string
|
// Database driver configuration. Defaults to sqlite
|
||||||
|
// when no database configuration specified.
|
||||||
|
datasource = config.String("database-source", "drone.sqlite")
|
||||||
|
driver = config.String("database-driver", "sqlite3")
|
||||||
|
|
||||||
open bool
|
// HTTP Server settings.
|
||||||
|
port = config.String("server-port", ":8000")
|
||||||
|
sslcrt = config.String("server-ssl-cert", "")
|
||||||
|
sslkey = config.String("server-ssl-key", "")
|
||||||
|
|
||||||
|
// Enable self-registration. When false, the system admin
|
||||||
|
// must grant user access.
|
||||||
|
open = config.Bool("registration-open", false)
|
||||||
|
|
||||||
// worker pool
|
|
||||||
workers *pool.Pool
|
workers *pool.Pool
|
||||||
|
|
||||||
// director
|
|
||||||
worker *director.Director
|
worker *director.Director
|
||||||
|
|
||||||
pub *pubsub.PubSub
|
pub *pubsub.PubSub
|
||||||
|
|
||||||
|
// Docker configuration details.
|
||||||
|
tlscacert = config.String("docker-tlscacert")
|
||||||
|
tlscert = config.String("docker-tlscert")
|
||||||
|
tlskey = config.String("docker-tlskey")
|
||||||
nodes StringArr
|
nodes StringArr
|
||||||
|
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
@ -74,30 +72,34 @@ var (
|
||||||
func main() {
|
func main() {
|
||||||
log.SetPriority(log.LOG_NOTICE)
|
log.SetPriority(log.LOG_NOTICE)
|
||||||
|
|
||||||
|
// Parses flags. The only flag that can be passed into the
|
||||||
|
// application is the location of the configuration (.toml) file.
|
||||||
|
var conf string
|
||||||
flag.StringVar(&conf, "config", "", "")
|
flag.StringVar(&conf, "config", "", "")
|
||||||
flag.StringVar(&prefix, "prefix", "DRONE_", "")
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
config.StringVar(&datasource, "database-source", "drone.sqlite")
|
|
||||||
config.StringVar(&driver, "database-driver", "sqlite3")
|
|
||||||
config.Var(&nodes, "worker-nodes")
|
config.Var(&nodes, "worker-nodes")
|
||||||
config.BoolVar(&open, "registration-open", false)
|
|
||||||
config.SetPrefix(prefix)
|
|
||||||
if err := config.Parse(conf); err != nil {
|
|
||||||
fmt.Println("Error parsing config", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup the remote services
|
// Parses config data. The config data can be stored in a config
|
||||||
|
// file (.toml format) or environment variables, or a combo.
|
||||||
|
config.SetPrefix("DRONE_")
|
||||||
|
config.Parse(conf)
|
||||||
|
|
||||||
|
// Setup the remote services. We need to execute these to register
|
||||||
|
// the remote plugins with the system.
|
||||||
|
//
|
||||||
|
// NOTE: this cannot be done via init() because they need to be
|
||||||
|
// executed after config.Parse
|
||||||
bitbucket.Register()
|
bitbucket.Register()
|
||||||
github.Register()
|
github.Register()
|
||||||
gitlab.Register()
|
gitlab.Register()
|
||||||
|
|
||||||
caps = map[string]bool{}
|
caps = map[string]bool{}
|
||||||
caps[capability.Registration] = open
|
caps[capability.Registration] = *open
|
||||||
|
|
||||||
// setup the database and cancel all pending
|
// setup the database and cancel all pending
|
||||||
// commits in the system.
|
// commits in the system.
|
||||||
db = database.MustConnect(driver, datasource)
|
db = database.MustConnect(*driver, *datasource)
|
||||||
go database.NewCommitstore(db).KillCommits()
|
go database.NewCommitstore(db).KillCommits()
|
||||||
|
|
||||||
// Create the worker, director and builders
|
// Create the worker, director and builders
|
||||||
|
@ -115,7 +117,7 @@ func main() {
|
||||||
|
|
||||||
pub = pubsub.NewPubSub()
|
pub = pubsub.NewPubSub()
|
||||||
|
|
||||||
// Include static resources
|
// create handler for static resources
|
||||||
assets := rice.MustFindBox("app").HTTPBox()
|
assets := rice.MustFindBox("app").HTTPBox()
|
||||||
assetserve := http.FileServer(rice.MustFindBox("app").HTTPBox())
|
assetserve := http.FileServer(rice.MustFindBox("app").HTTPBox())
|
||||||
http.Handle("/static/", http.StripPrefix("/static", assetserve))
|
http.Handle("/static/", http.StripPrefix("/static", assetserve))
|
||||||
|
@ -125,18 +127,17 @@ func main() {
|
||||||
|
|
||||||
// create the router and add middleware
|
// create the router and add middleware
|
||||||
mux := router.New()
|
mux := router.New()
|
||||||
//mux.Use(middleware.Recovery)
|
mux.Use(ContextMiddleware)
|
||||||
//mux.Use(middleware.Logger)
|
|
||||||
//mux.Use(middleware.NoCache)
|
|
||||||
mux.Use(middleware.SetHeaders)
|
mux.Use(middleware.SetHeaders)
|
||||||
mux.Use(middleware.SetUser)
|
mux.Use(middleware.SetUser)
|
||||||
mux.Use(ContextMiddleware)
|
|
||||||
http.Handle("/api/", mux)
|
http.Handle("/api/", mux)
|
||||||
|
|
||||||
if len(sslcert) == 0 {
|
// start the http server in either http or https mode,
|
||||||
panic(http.ListenAndServe(port, nil))
|
// depending on whether a certificate was provided.
|
||||||
|
if len(*sslcrt) == 0 {
|
||||||
|
panic(http.ListenAndServe(*port, nil))
|
||||||
} else {
|
} else {
|
||||||
panic(http.ListenAndServeTLS(port, sslcert, sslkey, nil))
|
panic(http.ListenAndServeTLS(*port, *sslcrt, *sslkey, nil))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue