From 0c3021473f923238eba3019795196dfb89107528 Mon Sep 17 00:00:00 2001 From: Thomas Anderson <127358482+zc-devs@users.noreply.github.com> Date: Sun, 18 Jun 2023 15:47:40 +0300 Subject: [PATCH] Added Woodpecker Host Config used for Webhooks (#1869) When SCM and Woodpecker are deployed in the same cluster, I want that SCM requests Woodpecker directly by internal URL. ![Webhook-host-diagram](https://github.com/woodpecker-ci/woodpecker/assets/127358482/c4689d55-839a-4731-95b3-5734ba561e5f) This PR adds optional URL used for Webhook calls. --- cmd/server/flags.go | 5 +++++ cmd/server/server.go | 5 +++++ docs/docs/30-administration/10-server-config.md | 7 +++++++ server/api/repo.go | 2 +- server/config.go | 1 + 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/server/flags.go b/cmd/server/flags.go index add5f55d4..bf5f704c9 100644 --- a/cmd/server/flags.go +++ b/cmd/server/flags.go @@ -45,6 +45,11 @@ var flags = []cli.Flag{ Name: "server-host", Usage: "server fully qualified url (://)", }, + &cli.StringFlag{ + EnvVars: []string{"WOODPECKER_WEBHOOK_HOST"}, + Name: "server-webhook-host", + Usage: "server fully qualified url for forge's Webhooks (://)", + }, &cli.StringFlag{ EnvVars: []string{"WOODPECKER_ROOT_URL"}, Name: "root-url", diff --git a/cmd/server/server.go b/cmd/server/server.go index 59f812fe0..f69acea4d 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -341,6 +341,11 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) { server.Config.Server.Key = c.String("server-key") server.Config.Server.AgentToken = c.String("agent-secret") server.Config.Server.Host = c.String("server-host") + if c.IsSet("server-webhook-host") { + server.Config.Server.WebhookHost = c.String("server-webhook-host") + } else { + server.Config.Server.WebhookHost = c.String("server-host") + } if c.IsSet("server-dev-oauth-host") { server.Config.Server.OAuthHost = c.String("server-dev-oauth-host") } else { diff --git a/docs/docs/30-administration/10-server-config.md b/docs/docs/30-administration/10-server-config.md index 282f6cc8e..7456b2576 100644 --- a/docs/docs/30-administration/10-server-config.md +++ b/docs/docs/30-administration/10-server-config.md @@ -131,6 +131,13 @@ Server fully qualified URL of the user-facing hostname. Example: `WOODPECKER_HOST=http://woodpecker.example.org` +### `WOODPECKER_WEBHOOK_HOST` +> Default: value from `WOODPECKER_HOST` config env + +Server fully qualified URL of the Webhook-facing hostname. + +Example: `WOODPECKER_WEBHOOK_HOST=http://woodpecker-server.cicd.svc.cluster.local:8000` + ### `WOODPECKER_SERVER_ADDR` > Default: `:8000` diff --git a/server/api/repo.go b/server/api/repo.go index 264f679d3..fb6dff90d 100644 --- a/server/api/repo.go +++ b/server/api/repo.go @@ -110,7 +110,7 @@ func PostRepo(c *gin.Context) { link := fmt.Sprintf( "%s/hook?access_token=%s", - server.Config.Server.Host, + server.Config.Server.WebhookHost, sig, ) diff --git a/server/config.go b/server/config.go index 581710f73..0e52e988b 100644 --- a/server/config.go +++ b/server/config.go @@ -59,6 +59,7 @@ var Config = struct { Cert string OAuthHost string Host string + WebhookHost string Port string PortTLS string AgentToken string