Skip to content

Commit

Permalink
Add option to disable version check in admin web UI (#3040)
Browse files Browse the repository at this point in the history
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
  • Loading branch information
6543 and qwerty287 authored Dec 27, 2023
1 parent 8280655 commit 74f6824
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 10 deletions.
5 changes: 5 additions & 0 deletions cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ var flags = append([]cli.Flag{
Name: "enable-swagger",
Value: true,
},
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_DISABLE_VERSION_CHECK"},
Usage: "Disable version check in admin web ui.",
Name: "skip-version-check",
},
&cli.StringSliceFlag{
EnvVars: []string{"WOODPECKER_ADDONS"},
Name: "addons",
Expand Down
3 changes: 2 additions & 1 deletion cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) error {
server.Config.Pipeline.Networks = c.StringSlice("network")
server.Config.Pipeline.Volumes = c.StringSlice("volume")
server.Config.Pipeline.Privileged = c.StringSlice("escalate")
server.Config.Server.EnableSwagger = c.Bool("enable-swagger")
server.Config.WebUI.EnableSwagger = c.Bool("enable-swagger")
server.Config.WebUI.SkipVersionCheck = c.Bool("skip-version-check")

// prometheus
server.Config.Prometheus.AuthToken = c.String("prometheus-auth-token")
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/30-administration/10-server-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,12 @@ Specify how many seconds before timeout when fetching the Woodpecker configurati
Enable the Swagger UI for API documentation.

### `WOODPECKER_DISABLE_VERSION_CHECK`

> Default: false
Disable version check in admin web UI.

---

### `WOODPECKER_GITHUB_...`
Expand Down
5 changes: 4 additions & 1 deletion server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ var Config = struct {
RootPath string
CustomCSSFile string
CustomJsFile string
EnableSwagger bool
}
WebUI struct {
EnableSwagger bool
SkipVersionCheck bool
}
Prometheus struct {
AuthToken string
Expand Down
2 changes: 1 addition & 1 deletion server/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func Load(noRouteHandler http.HandlerFunc, middleware ...gin.HandlerFunc) http.H
}

apiRoutes(base)
if server.Config.Server.EnableSwagger {
if server.Config.WebUI.EnableSwagger {
setupSwaggerConfigAndRoutes(e)
}

Expand Down
14 changes: 8 additions & 6 deletions server/web/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ func Config(c *gin.Context) {
}

configData := map[string]any{
"user": user,
"csrf": csrf,
"version": version.String(),
"forge": server.Config.Services.Forge.Name(),
"root_path": server.Config.Server.RootPath,
"enable_swagger": server.Config.Server.EnableSwagger,
"user": user,
"csrf": csrf,
"version": version.String(),
"skip_version_check": server.Config.WebUI.SkipVersionCheck,
"forge": server.Config.Services.Forge.Name(),
"root_path": server.Config.Server.RootPath,
"enable_swagger": server.Config.WebUI.EnableSwagger,
}

// default func map with json parser.
Expand Down Expand Up @@ -75,4 +76,5 @@ window.WOODPECKER_VERSION = "{{ .version }}";
window.WOODPECKER_FORGE = "{{ .forge }}";
window.WOODPECKER_ROOT_PATH = "{{ .root_path }}";
window.WOODPECKER_ENABLE_SWAGGER = {{ .enable_swagger }};
window.WOODPECKER_SKIP_VERSION_CHECK = {{ .skip_version_check }}
`
2 changes: 2 additions & 0 deletions web/src/compositions/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare global {
interface Window {
WOODPECKER_USER: User | undefined;
WOODPECKER_VERSION: string | undefined;
WOODPECKER_SKIP_VERSION_CHECK: boolean | undefined;
WOODPECKER_CSRF: string | undefined;
WOODPECKER_FORGE: 'github' | 'gitlab' | 'gitea' | 'bitbucket' | undefined;
WOODPECKER_ROOT_PATH: string | undefined;
Expand All @@ -14,6 +15,7 @@ declare global {
export default () => ({
user: window.WOODPECKER_USER || null,
version: window.WOODPECKER_VERSION,
skipVersionCheck: window.WOODPECKER_SKIP_VERSION_CHECK || false,
csrf: window.WOODPECKER_CSRF || null,
forge: window.WOODPECKER_FORGE || null,
rootPath: window.WOODPECKER_ROOT_PATH || '',
Expand Down
2 changes: 1 addition & 1 deletion web/src/compositions/useVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function useVersion() {
const usesNext = current.startsWith('next');

const { user } = useAuthentication();
if (!user?.admin) {
if (config.skipVersionCheck || !user?.admin) {
version.value = {
latest: undefined,
current,
Expand Down

0 comments on commit 74f6824

Please sign in to comment.