diff --git a/cmd/server/flags.go b/cmd/server/flags.go index d56899612..08cff5842 100644 --- a/cmd/server/flags.go +++ b/cmd/server/flags.go @@ -38,12 +38,12 @@ var flags = append([]cli.Flag{ &cli.StringFlag{ EnvVars: []string{"WOODPECKER_HOST"}, Name: "server-host", - Usage: "server fully qualified url (://)", + 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 (://)", + Usage: "server fully qualified url for forge's Webhooks (://[/])", }, &cli.StringFlag{ EnvVars: []string{"WOODPECKER_ROOT_PATH", "WOODPECKER_ROOT_URL"}, @@ -450,7 +450,7 @@ var flags = append([]cli.Flag{ &cli.StringFlag{ EnvVars: []string{"WOODPECKER_DEV_OAUTH_HOST"}, Name: "server-dev-oauth-host", - Usage: "server fully qualified url (://) used for oauth redirect (used for development)", + Usage: "server fully qualified url (://[/]) used for oauth redirect (used for development)", Value: "", Hidden: true, }, diff --git a/cmd/server/server.go b/cmd/server/server.go index 0753deee9..520340df2 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -344,7 +344,13 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) { server.Config.Server.StatusContext = c.String("status-context") server.Config.Server.StatusContextFormat = c.String("status-context-format") server.Config.Server.SessionExpires = c.Duration("session-expires") - rootPath := strings.TrimSuffix(c.String("root-path"), "/") + rootPath := c.String("root-path") + if !c.IsSet("root-path") { + // Extract RootPath from Host... + u, _ := url.Parse(server.Config.Server.Host) + rootPath = u.Path + } + rootPath = strings.TrimSuffix(rootPath, "/") if rootPath != "" && !strings.HasPrefix(rootPath, "/") { rootPath = "/" + rootPath } diff --git a/docs/docs/30-administration/00-setup.md b/docs/docs/30-administration/00-setup.md index c8f4276f5..662c3835b 100644 --- a/docs/docs/30-administration/00-setup.md +++ b/docs/docs/30-administration/00-setup.md @@ -93,7 +93,6 @@ services: environment: - [...] + - WOODPECKER_HOST=${WOODPECKER_HOST} -+ - WOODPECKER_HOST=${WOODPECKER_HOST} ``` Woodpecker can also have its port's configured. It uses a separate port for gRPC and for HTTP. The agent performs gRPC calls and connects to the gRPC port. diff --git a/docs/docs/30-administration/10-server-config.md b/docs/docs/30-administration/10-server-config.md index 69121ad66..33a010914 100644 --- a/docs/docs/30-administration/10-server-config.md +++ b/docs/docs/30-administration/10-server-config.md @@ -215,14 +215,14 @@ Disable colored debug output. ### `WOODPECKER_HOST` > Default: empty -Server fully qualified URL of the user-facing hostname. +Server fully qualified URL of the user-facing hostname and path prefix. -Example: `WOODPECKER_HOST=http://woodpecker.example.org` +Example: `WOODPECKER_HOST=http://woodpecker.example.org` or `WOODPECKER_HOST=http://example.org/woodpecker` ### `WOODPECKER_WEBHOOK_HOST` > Default: value from `WOODPECKER_HOST` config env -Server fully qualified URL of the Webhook-facing hostname. +Server fully qualified URL of the Webhook-facing hostname and path prefix. Example: `WOODPECKER_WEBHOOK_HOST=http://woodpecker-server.cicd.svc.cluster.local:8000` @@ -529,7 +529,7 @@ Specify a configuration service endpoint, see [Configuration Extension](./100-ex Specify how many seconds before timeout when fetching the Woodpecker configuration from a Forge ### `WOODPECKER_ROOT_PATH` -> Default: `` +> Default: extracted from `WOODPECKER_HOST` Server URL path prefix (used for statics loading when having a url path prefix), should start with `/` diff --git a/server/api/repo.go b/server/api/repo.go index fc92d17cc..e4ea4322c 100644 --- a/server/api/repo.go +++ b/server/api/repo.go @@ -389,7 +389,7 @@ func DeleteRepo(c *gin.Context) { } } - if err := server.Config.Services.Forge.Deactivate(c, user, repo, server.Config.Server.Host); err != nil { + if err := server.Config.Services.Forge.Deactivate(c, user, repo, server.Config.Server.WebhookHost); err != nil { _ = c.AbortWithError(http.StatusInternalServerError, err) return } @@ -534,7 +534,7 @@ func MoveRepo(c *gin.Context) { } // reconstruct the link - host := server.Config.Server.Host + host := server.Config.Server.WebhookHost link := fmt.Sprintf( "%s/api/hook?access_token=%s", host, diff --git a/server/forge/bitbucket/bitbucket.go b/server/forge/bitbucket/bitbucket.go index 81b5e6a86..a8e6ca3a8 100644 --- a/server/forge/bitbucket/bitbucket.go +++ b/server/forge/bitbucket/bitbucket.go @@ -421,7 +421,7 @@ func (c *config) newOAuth2Config() *oauth2.Config { AuthURL: fmt.Sprintf("%s/site/oauth2/authorize", c.url), TokenURL: fmt.Sprintf("%s/site/oauth2/access_token", c.url), }, - RedirectURL: fmt.Sprintf("%s%s/authorize", server.Config.Server.OAuthHost, server.Config.Server.RootPath), + RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost), } } diff --git a/server/forge/gitea/gitea.go b/server/forge/gitea/gitea.go index 4c60718ea..13f29c324 100644 --- a/server/forge/gitea/gitea.go +++ b/server/forge/gitea/gitea.go @@ -103,7 +103,7 @@ func (c *Gitea) oauth2Config(ctx context.Context) (*oauth2.Config, context.Conte AuthURL: fmt.Sprintf(authorizeTokenURL, c.url), TokenURL: fmt.Sprintf(accessTokenURL, c.url), }, - RedirectURL: fmt.Sprintf("%s%s/authorize", server.Config.Server.OAuthHost, server.Config.Server.RootPath), + RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost), }, context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{ diff --git a/server/forge/github/github.go b/server/forge/github/github.go index 48775add5..53c65bb68 100644 --- a/server/forge/github/github.go +++ b/server/forge/github/github.go @@ -400,9 +400,9 @@ func (c *client) newConfig(req *http.Request) *oauth2.Config { intendedURL := req.URL.Query()["url"] if len(intendedURL) > 0 { - redirect = fmt.Sprintf("%s%s/authorize?url=%s", server.Config.Server.OAuthHost, server.Config.Server.RootPath, intendedURL[0]) + redirect = fmt.Sprintf("%s/authorize?url=%s", server.Config.Server.OAuthHost, intendedURL[0]) } else { - redirect = fmt.Sprintf("%s%s/authorize", server.Config.Server.OAuthHost, server.Config.Server.RootPath) + redirect = fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost) } return &oauth2.Config{ diff --git a/server/forge/gitlab/gitlab.go b/server/forge/gitlab/gitlab.go index c34b33dc7..ae25f6cf2 100644 --- a/server/forge/gitlab/gitlab.go +++ b/server/forge/gitlab/gitlab.go @@ -93,7 +93,7 @@ func (g *GitLab) oauth2Config(ctx context.Context) (*oauth2.Config, context.Cont TokenURL: fmt.Sprintf("%s/oauth/token", g.url), }, Scopes: []string{defaultScope}, - RedirectURL: fmt.Sprintf("%s%s/authorize", server.Config.Server.OAuthHost, server.Config.Server.RootPath), + RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost), }, context.WithValue(ctx, oauth2.HTTPClient, &http.Client{Transport: &http.Transport{