Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of WOODPECKER_ROOT_PATH #2485

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ var flags = append([]cli.Flag{
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_HOST"},
Name: "server-host",
Usage: "server fully qualified url (<scheme>://<host>)",
Usage: "server fully qualified url (<scheme>://<host>[/<prefixpath>])",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_WEBHOOK_HOST"},
Name: "server-webhook-host",
Usage: "server fully qualified url for forge's Webhooks (<scheme>://<host>)",
Usage: "server fully qualified url for forge's Webhooks (<scheme>://<host>[/<prefixpath>])",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_ROOT_PATH", "WOODPECKER_ROOT_URL"},
Expand Down Expand Up @@ -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 (<scheme>://<host>) used for oauth redirect (used for development)",
Usage: "server fully qualified url (<scheme>://<host>[/<prefixpath>]) used for oauth redirect (used for development)",
Value: "",
Hidden: true,
},
Expand Down
8 changes: 7 additions & 1 deletion cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion docs/docs/30-administration/00-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/30-administration/10-server-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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`
tomix1024 marked this conversation as resolved.
Show resolved Hide resolved

Server URL path prefix (used for statics loading when having a url path prefix), should start with `/`

Expand Down
4 changes: 2 additions & 2 deletions server/api/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/forge/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 1 addition & 1 deletion server/forge/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions server/forge/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion server/forge/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down