forked from NYANDEV/forgejo
ffb9ffdc0e
- Use TXT records in order to determine the latest available version. - This addresses a valid privacy issue, as with HTTP requests the server can keep track(estimated) of how many instances are using Forgejo, with DNS that's basically not possible as the server will never receive any data, as the only ones receiving data are DNS resolvers. (cherry picked from commit 0baefb546ab96bc3c06d90feffdb14873c2c2a3a) (cherry picked from commit e8ee41880b775532e6a68bd2052ed96d369dee78) (cherry picked from commit 7eca4f3bf1faa3f063c9668d1bb354b842361007) (cherry picked from commit 6dde3992dc504f105f2285c34fa6445fa24da0b1) (cherry picked from commit fb3a37fbfc73d35e3ba8d793b6051aeddcbb0634) (cherry picked from commit 8304af1e9d94b89ee700b0d454d74d0dc5cfac64) (cherry picked from commit 0543a7d12a4bac012db8b9e683e879e6f265a9dc) (cherry picked from commit c3a22933b7ca8201c96267d360281848fb2a1c7e) (cherry picked from commit e24370769413aebe96ba6cfb230da3c2c33e39f4) (cherry picked from commit 7eb6d1bcf7a0bdae0cbbf06136854d0b29c54899) (cherry picked from commit 1d7b9535cd73bffda5defd143c25e514cc55dee8) (cherry picked from commit 05920dce67808ae346c4e9cd9a41c9942e857bc6) (cherry picked from commit f173f27d7c3bf36c54b7e715a61b2308d1b0d277) (cherry picked from commit 90e1c9340e72f08e67293647cf5f19b3e3571909) (cherry picked from commit de68610ea70b81146f6412e42d72b97aad0428ae) (cherry picked from commit 8d5757ea0459cffeb885462b7a9d1e1c630e1f16) (cherry picked from commit c7a7fff316c1a88ba9b0984114a25cecfac56bce) (cherry picked from commit 39ac8b8fc164090eacd5870bf78ea863d2add5fa) (cherry picked from commit 2f65c02905b529bd1bed617c7d0fc3510a9b2a95) (cherry picked from commit 74b5133374eb3e16b995c88d63d1e01280a8cfb4) (cherry picked from commit e31c34e89349668a8312aa6cafd3f7ed69f51aca)
232 lines
7.3 KiB
Go
232 lines
7.3 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cron
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
|
"code.gitea.io/gitea/models/db"
|
|
"code.gitea.io/gitea/models/system"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/modules/git"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/updatechecker"
|
|
repo_service "code.gitea.io/gitea/services/repository"
|
|
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
|
user_service "code.gitea.io/gitea/services/user"
|
|
)
|
|
|
|
func registerDeleteInactiveUsers() {
|
|
RegisterTaskFatal("delete_inactive_accounts", &OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@annually",
|
|
},
|
|
OlderThan: time.Minute * time.Duration(setting.Service.ActiveCodeLives),
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
return user_service.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
|
|
})
|
|
}
|
|
|
|
func registerDeleteRepositoryArchives() {
|
|
RegisterTaskFatal("delete_repo_archives", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@annually",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return archiver_service.DeleteRepositoryArchives(ctx)
|
|
})
|
|
}
|
|
|
|
func registerGarbageCollectRepositories() {
|
|
type RepoHealthCheckConfig struct {
|
|
BaseConfig
|
|
Timeout time.Duration
|
|
Args []string `delim:" "`
|
|
}
|
|
RegisterTaskFatal("git_gc_repos", &RepoHealthCheckConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
},
|
|
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
|
|
Args: setting.Git.GCArgs,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
rhcConfig := config.(*RepoHealthCheckConfig)
|
|
// the git args are set by config, they can be safe to be trusted
|
|
return repo_service.GitGcRepos(ctx, rhcConfig.Timeout, git.ToTrustedCmdArgs(rhcConfig.Args))
|
|
})
|
|
}
|
|
|
|
func registerRewriteAllPublicKeys() {
|
|
RegisterTaskFatal("resync_all_sshkeys", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(_ context.Context, _ *user_model.User, _ Config) error {
|
|
return asymkey_model.RewriteAllPublicKeys()
|
|
})
|
|
}
|
|
|
|
func registerRewriteAllPrincipalKeys() {
|
|
RegisterTaskFatal("resync_all_sshprincipals", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(_ context.Context, _ *user_model.User, _ Config) error {
|
|
return asymkey_model.RewriteAllPrincipalKeys(db.DefaultContext)
|
|
})
|
|
}
|
|
|
|
func registerRepositoryUpdateHook() {
|
|
RegisterTaskFatal("resync_all_hooks", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return repo_service.SyncRepositoryHooks(ctx)
|
|
})
|
|
}
|
|
|
|
func registerReinitMissingRepositories() {
|
|
RegisterTaskFatal("reinit_missing_repos", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return repo_service.ReinitMissingRepositories(ctx)
|
|
})
|
|
}
|
|
|
|
func registerDeleteMissingRepositories() {
|
|
RegisterTaskFatal("delete_missing_repos", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, user *user_model.User, _ Config) error {
|
|
return repo_service.DeleteMissingRepositories(ctx, user)
|
|
})
|
|
}
|
|
|
|
func registerRemoveRandomAvatars() {
|
|
RegisterTaskFatal("delete_generated_repository_avatars", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return repo_service.RemoveRandomAvatars(ctx)
|
|
})
|
|
}
|
|
|
|
func registerDeleteOldActions() {
|
|
RegisterTaskFatal("delete_old_actions", &OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 168h",
|
|
},
|
|
OlderThan: 365 * 24 * time.Hour,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
return activities_model.DeleteOldActions(olderThanConfig.OlderThan)
|
|
})
|
|
}
|
|
|
|
func registerUpdateGiteaChecker() {
|
|
type UpdateCheckerConfig struct {
|
|
BaseConfig
|
|
HTTPEndpoint string
|
|
DomainEndpoint string
|
|
}
|
|
RegisterTaskFatal("update_checker", &UpdateCheckerConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 168h",
|
|
},
|
|
HTTPEndpoint: "https://dl.gitea.com/gitea/version.json",
|
|
DomainEndpoint: "release.forgejo.org",
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
updateCheckerConfig := config.(*UpdateCheckerConfig)
|
|
return updatechecker.GiteaUpdateChecker(updateCheckerConfig.HTTPEndpoint, updateCheckerConfig.DomainEndpoint)
|
|
})
|
|
}
|
|
|
|
func registerDeleteOldSystemNotices() {
|
|
RegisterTaskFatal("delete_old_system_notices", &OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 168h",
|
|
},
|
|
OlderThan: 365 * 24 * time.Hour,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
return system.DeleteOldSystemNotices(olderThanConfig.OlderThan)
|
|
})
|
|
}
|
|
|
|
func registerGCLFS() {
|
|
if !setting.LFS.StartServer {
|
|
return
|
|
}
|
|
type GCLFSConfig struct {
|
|
OlderThanConfig
|
|
LastUpdatedMoreThanAgo time.Duration
|
|
NumberToCheckPerRepo int64
|
|
ProportionToCheckPerRepo float64
|
|
}
|
|
|
|
RegisterTaskFatal("gc_lfs", &GCLFSConfig{
|
|
OlderThanConfig: OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 24h",
|
|
},
|
|
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
|
|
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
|
|
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
|
|
// changes in new branches that might lead to lfs objects becoming temporarily unassociated with git
|
|
// objects.
|
|
//
|
|
// It is likely that a week is potentially excessive but it should definitely be enough that any
|
|
// unassociated LFS object is genuinely unassociated.
|
|
OlderThan: 24 * time.Hour * 7,
|
|
},
|
|
// Only GC things that haven't been looked at in the past 3 days
|
|
LastUpdatedMoreThanAgo: 24 * time.Hour * 3,
|
|
NumberToCheckPerRepo: 100,
|
|
ProportionToCheckPerRepo: 0.6,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
gcLFSConfig := config.(*GCLFSConfig)
|
|
return repo_service.GarbageCollectLFSMetaObjects(ctx, repo_service.GarbageCollectLFSMetaObjectsOptions{
|
|
AutoFix: true,
|
|
OlderThan: time.Now().Add(-gcLFSConfig.OlderThan),
|
|
UpdatedLessRecentlyThan: time.Now().Add(-gcLFSConfig.LastUpdatedMoreThanAgo),
|
|
})
|
|
})
|
|
}
|
|
|
|
func initExtendedTasks() {
|
|
registerDeleteInactiveUsers()
|
|
registerDeleteRepositoryArchives()
|
|
registerGarbageCollectRepositories()
|
|
registerRewriteAllPublicKeys()
|
|
registerRewriteAllPrincipalKeys()
|
|
registerRepositoryUpdateHook()
|
|
registerReinitMissingRepositories()
|
|
registerDeleteMissingRepositories()
|
|
registerRemoveRandomAvatars()
|
|
registerDeleteOldActions()
|
|
registerUpdateGiteaChecker()
|
|
registerDeleteOldSystemNotices()
|
|
registerGCLFS()
|
|
}
|