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

Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
6543 2023-12-27 22:16:15 +01:00 committed by GitHub
parent 8280655e0f
commit 74f6824d03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 10 deletions

View file

@ -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",

View file

@ -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")

View file

@ -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_...`

View file

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

View file

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

View file

@ -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.
@ -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 }}
`

View file

@ -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;
@ -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 || '',

View file

@ -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,