mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-05 03:28:30 +01:00
6fc17ad37b
- 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 commit0baefb546a
) (cherry picked from commite8ee41880b
) (cherry picked from commit7eca4f3bf1
) (cherry picked from commit6dde3992dc
) (cherry picked from commitfb3a37fbfc
) (cherry picked from commit8304af1e9d
) (cherry picked from commit0543a7d12a
) (cherry picked from commitc3a22933b7
) (cherry picked from commite243707694
) (cherry picked from commit7eb6d1bcf7
) (cherry picked from commit1d7b9535cd
) (cherry picked from commit05920dce67
) (cherry picked from commitf173f27d7c
) (cherry picked from commit90e1c9340e
) (cherry picked from commitde68610ea7
) (cherry picked from commit8d5757ea04
) (cherry picked from commitc7a7fff316
) (cherry picked from commit39ac8b8fc1
) (cherry picked from commit9889203301
) [PRIVACY]: Adjust update checker description - Resolves #323 - Adjust the description of the update check function on the installation page to describe the privacy method instead of the HTTP method by checking gitea.io (cherry picked from commit61eae5b105
) (cherry picked from commit091def20a1
) (cherry picked from commitd5d11bf45a
) (cherry picked from commit71863d4707
) (cherry picked from commit11ece4aab1
) (cherry picked from commitafdd7e714f
) (cherry picked from commit39170e2f1d
) (cherry picked from commit4b3a52aab8
) (cherry picked from commit9d763c5fc8
) (cherry picked from commit638db15482
) (cherry picked from commita52bfdd8e7
) (cherry picked from commitdc93d00e85
) (cherry picked from commit0bc4b3508c
) (cherry picked from commit3f760d85a4
) (cherry picked from commitecc2716785
) (cherry picked from commit6334d5677e
) Conflicts: modules/updatechecker/update_checker.go UpdateRemoteVersion now has a context argument. However, in the updated code from Gitea the context comes from the HTTP request and does not actually provide any useful context. Replace that with context.Background() (cherry picked from commitca2200767e
) (cherry picked from commitf46feca224
) (cherry picked from commita800a66ca8
) (cherry picked from commit21f017454e
) (cherry picked from commit762d18e09a
) (cherry picked from commit6d28e120c1
) (cherry picked from commit4fcd7e7cbf
) (cherry picked from commit9516285112
) (cherry picked from commit0dd752a262
) (cherry picked from commitb1f1af7fe0
) (cherry picked from commit71937deaa5
) (cherry picked from commit93e41a7823
) (cherry picked from commitf497ed30cf
) (cherry picked from commitbff3346f7d
) (cherry picked from commit906ae19c0f
)
243 lines
7.7 KiB
Go
243 lines
7.7 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/system"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/modules/git"
|
|
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
|
|
"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(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return asymkey_model.RewriteAllPublicKeys(ctx)
|
|
})
|
|
}
|
|
|
|
func registerRewriteAllPrincipalKeys() {
|
|
RegisterTaskFatal("resync_all_sshprincipals", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return asymkey_model.RewriteAllPrincipalKeys(ctx)
|
|
})
|
|
}
|
|
|
|
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(ctx, 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(ctx, 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 registerRebuildIssueIndexer() {
|
|
RegisterTaskFatal("rebuild_issue_indexer", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@annually",
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
return issue_indexer.PopulateIssueIndexer(ctx)
|
|
})
|
|
}
|
|
|
|
func initExtendedTasks() {
|
|
registerDeleteInactiveUsers()
|
|
registerDeleteRepositoryArchives()
|
|
registerGarbageCollectRepositories()
|
|
registerRewriteAllPublicKeys()
|
|
registerRewriteAllPrincipalKeys()
|
|
registerRepositoryUpdateHook()
|
|
registerReinitMissingRepositories()
|
|
registerDeleteMissingRepositories()
|
|
registerRemoveRandomAvatars()
|
|
registerDeleteOldActions()
|
|
registerUpdateGiteaChecker()
|
|
registerDeleteOldSystemNotices()
|
|
registerGCLFS()
|
|
registerRebuildIssueIndexer()
|
|
}
|