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

Add option to disable version check in admin web UI #3040

Merged
merged 6 commits into from
Dec 27, 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
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 @@
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")

Check warning on line 374 in cmd/server/server.go

View check run for this annotation

Codecov / codecov/patch

cmd/server/server.go#L373-L374

Added lines #L373 - L374 were not covered by tests

// 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 @@
}

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,

Check warning on line 49 in server/web/config.go

View check run for this annotation

Codecov / codecov/patch

server/web/config.go#L43-L49

Added lines #L43 - L49 were not covered by tests
}

// default func map with json parser.
Expand Down Expand Up @@ -75,4 +76,5 @@
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