Allow to configure port for SSL (#1735)

Co-authored-by: Mehdi Katranji <hello@mek.yt>
Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
meak 2023-05-11 06:11:10 +02:00 committed by GitHub
parent 6d2240b2e6
commit 41a50ae915
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 2 deletions

View file

@ -56,6 +56,12 @@ var flags = []cli.Flag{
Usage: "server address", Usage: "server address",
Value: ":8000", Value: ":8000",
}, },
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_SERVER_ADDR_TLS"},
Name: "server-addr-tls",
Usage: "port https with tls (:443)",
Value: ":443",
},
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"WOODPECKER_SERVER_CERT"}, EnvVars: []string{"WOODPECKER_SERVER_CERT"},
Name: "server-cert", Name: "server-cert",

View file

@ -210,7 +210,7 @@ func run(c *cli.Context) error {
// start the server with tls enabled // start the server with tls enabled
g.Go(func() error { g.Go(func() error {
serve := &http.Server{ serve := &http.Server{
Addr: ":https", Addr: server.Config.Server.PortTLS,
Handler: handler, Handler: handler,
TLSConfig: &tls.Config{ TLSConfig: &tls.Config{
NextProtos: []string{"h2", "http/1.1"}, NextProtos: []string{"h2", "http/1.1"},
@ -236,7 +236,7 @@ func run(c *cli.Context) error {
} }
g.Go(func() error { g.Go(func() error {
return http.ListenAndServe(":http", http.HandlerFunc(redirect)) return http.ListenAndServe(server.Config.Server.Port, http.HandlerFunc(redirect))
}) })
} else if c.Bool("lets-encrypt") { } else if c.Bool("lets-encrypt") {
// start the server with lets-encrypt // start the server with lets-encrypt
@ -350,6 +350,7 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) {
server.Config.Server.OAuthHost = c.String("server-host") server.Config.Server.OAuthHost = c.String("server-host")
} }
server.Config.Server.Port = c.String("server-addr") server.Config.Server.Port = c.String("server-addr")
server.Config.Server.PortTLS = c.String("server-addr-tls")
server.Config.Server.Docs = c.String("docs") server.Config.Server.Docs = c.String("docs")
server.Config.Server.StatusContext = c.String("status-context") server.Config.Server.StatusContext = c.String("status-context")
server.Config.Server.StatusContextFormat = c.String("status-context-format") server.Config.Server.StatusContextFormat = c.String("status-context-format")

View file

@ -136,6 +136,11 @@ Example: `WOODPECKER_HOST=http://woodpecker.example.org`
Configures the HTTP listener port. Configures the HTTP listener port.
### `WOODPECKER_SERVER_ADDR_TLS`
> Default: `:443`
Configures the HTTPS listener port when SSL is enabled.
### `WOODPECKER_SERVER_CERT` ### `WOODPECKER_SERVER_CERT`
> Default: empty > Default: empty

View file

@ -61,6 +61,7 @@ var Config = struct {
OAuthHost string OAuthHost string
Host string Host string
Port string Port string
PortTLS string
AgentToken string AgentToken string
Docs string Docs string
StatusContext string StatusContext string