-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Limit repo size #21820
base: main
Are you sure you want to change the base?
Limit repo size #21820
Changes from all commits
bb96349
56b92a1
2f65545
7c31cfc
6a2e670
df60de2
136b631
20bfff3
75585de
036e55c
62d3c05
ee31efc
36b43fe
762799b
b391383
04de706
d9ab187
31359b4
4c0921e
1c7b3b6
a16f5fa
af2e3a3
4687f0c
d1368ec
4256bdc
cdc5a2c
e26bcfc
2763393
e7ab661
6060ae1
8383ec5
562bc27
d13d457
80fa68b
4a31279
fe168a4
f8b1413
ac99056
0666202
c20faef
3429b99
bcea146
7aeb909
dd0246e
64f5b94
9a36273
cc2521c
8adfb6d
b00f27e
37725e4
7b4e90b
9da8b9d
82dcd0c
ae06851
e3b4628
8494f19
0afa267
211c085
8293e7f
920fb58
f583b8f
8a84718
4b09713
3f8bdd1
ab5ffc0
83cc033
d98a62a
7f28229
4793882
3592ae7
1765ea3
a22b738
66c476e
d843a67
0231760
82f3e2d
2a1abe5
3d0004a
414c902
31600a0
703ba07
c55ccfd
9e5f2fd
80f8977
8ac833a
c31c510
8750728
c2fc283
4936e49
e9c29f8
57c94e6
656a3dc
ef760d7
51a7697
2cbdee0
88e74d6
7120c30
db5a8da
08c65ff
ab3097d
ed4865c
c96ec8d
fd73ace
256173f
6e99cf4
a32f797
7bc9554
22bb76c
a08c6fe
64f6dd6
20d4d4f
39ade30
0c3a46f
ccc564a
851c988
649da24
44df2b6
9c9f75f
cdf5946
eac9822
4b709c6
7240e3a
c203d2c
bc1cb65
9014d9f
79251d5
bc051a3
b521d36
9bf945f
efd3596
410d0cd
236681b
918325f
0e05c2e
e5a04cd
e9b8e6f
8097699
23a492d
f810b42
cfd013f
aec62fa
b709876
e1267d5
3612140
006f216
0fee4f4
ecdc2a7
807da90
4b6a77c
bf1870d
748dbd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
date: "2023-05-24T13:00:00+00:00" | ||
title: "Per repository size limit" | ||
slug: "repo-size-limit" | ||
weight: 12 | ||
toc: false | ||
draft: false | ||
aliases: | ||
- /en-us/repo-size-limit | ||
menu: | ||
sidebar: | ||
parent: "administration" | ||
name: "Per repository size limit" | ||
weight: 12 | ||
identifier: "repo-size-limit" | ||
--- | ||
|
||
# Gitea per repository size limit setup | ||
|
||
To use Gitea's experimental built-in per repository size limit support, Administrator must update the `app.ini` file: | ||
|
||
```ini | ||
;; Enable applying a global size limit defined by REPO_SIZE_LIMIT. Each repository can have a value that overrides the global limit | ||
;; "false" means no limit will be enforced, even if specified on a repository | ||
ENABLE_SIZE_LIMIT = true | ||
|
||
;; Specify a global repository size limit in bytes to apply for each repository. 0 - No limit | ||
;; If repository has it's own limit set in UI it will override the global setting | ||
;; Standard units of measurements for size can be used like B, KB, KiB, ... , EB, EiB, ... | ||
REPO_SIZE_LIMIT = 500 MB | ||
|
||
This setting is persistent. | ||
|
||
The size limitation is triggered when repository `disk size` + `new commit size` > `defined repository size limit` | ||
|
||
If size limitation is triggered the feature would prevent commits that increase repository size on disk | ||
of gitea server and allow those that decrease it | ||
|
||
# Gitea per repository size limit setup in UI | ||
|
||
1. For Gitea admin it is possible during runtime to enable/disable limit size feature, change the global size limit on the fly. | ||
**This setting is not persistent across restarts** | ||
|
||
`Admin panel/Site settings` -> `Repository management` | ||
|
||
Persistance can be achieved if the limit is maintained by editing `app.ini` file | ||
|
||
2. The individually set per repository limit in `Settings` of the | ||
repository would take precedence over global limit when the size limit | ||
feature is enabled. Only admin can modify those limits | ||
|
||
**Note**: Size checking for large repositories is time consuming operation so time of push under size limit might increase up to a minute depending on your server hardware |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_22 //nolint | ||
|
||
import ( | ||
"xorm.io/xorm" | ||
) | ||
|
||
func AddSizeLimitOnRepo(x *xorm.Engine) error { | ||
type Repository struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
SizeLimit int64 `xorm:"NOT NULL DEFAULT 0"` | ||
} | ||
|
||
return x.Sync2(new(Repository)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,6 +236,74 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error { | |
return nil | ||
} | ||
|
||
// CountObject represents repository count objects report | ||
type CountObject struct { | ||
Count int64 | ||
Size int64 | ||
InPack int64 | ||
Packs int64 | ||
SizePack int64 | ||
PrunePack int64 | ||
Garbage int64 | ||
SizeGarbage int64 | ||
} | ||
|
||
const ( | ||
statCount = "count: " | ||
statSize = "size: " | ||
statInpack = "in-pack: " | ||
statPacks = "packs: " | ||
statSizePack = "size-pack: " | ||
statPrunePackage = "prune-package: " | ||
statGarbage = "garbage: " | ||
statSizeGarbage = "size-garbage: " | ||
) | ||
|
||
// CountObjects returns the results of git count-objects on the repoPath | ||
func CountObjects(ctx context.Context, repoPath string) (*CountObject, error) { | ||
return CountObjectsWithEnv(ctx, repoPath, nil) | ||
} | ||
|
||
// CountObjectsWithEnv returns the results of git count-objects on the repoPath with custom env setup | ||
func CountObjectsWithEnv(ctx context.Context, repoPath string, env []string) (*CountObject, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @KN4CK3R would we need this into this PR or it's ok to add later? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KN4CK3R could you please advise if it is still a "may" on this item or it is actually "must"? |
||
cmd := NewCommand(ctx, "count-objects", "-v") | ||
stdout, _, err := cmd.RunStdString(&RunOpts{Dir: repoPath, Env: env}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return parseSize(stdout), nil | ||
} | ||
|
||
// parseSize parses the output from count-objects and return a CountObject | ||
func parseSize(objects string) *CountObject { | ||
repoSize := new(CountObject) | ||
for _, line := range strings.Split(objects, "\n") { | ||
switch { | ||
case strings.HasPrefix(line, statCount): | ||
repoSize.Count, _ = strconv.ParseInt(line[7:], 10, 64) | ||
case strings.HasPrefix(line, statSize): | ||
number, _ := strconv.ParseInt(line[6:], 10, 64) | ||
repoSize.Size = number * 1024 | ||
case strings.HasPrefix(line, statInpack): | ||
repoSize.InPack, _ = strconv.ParseInt(line[9:], 10, 64) | ||
case strings.HasPrefix(line, statPacks): | ||
repoSize.Packs, _ = strconv.ParseInt(line[7:], 10, 64) | ||
case strings.HasPrefix(line, statSizePack): | ||
number, _ := strconv.ParseInt(line[11:], 10, 64) | ||
repoSize.SizePack = number * 1024 | ||
case strings.HasPrefix(line, statPrunePackage): | ||
repoSize.PrunePack, _ = strconv.ParseInt(line[16:], 10, 64) | ||
case strings.HasPrefix(line, statGarbage): | ||
repoSize.Garbage, _ = strconv.ParseInt(line[9:], 10, 64) | ||
case strings.HasPrefix(line, statSizeGarbage): | ||
number, _ := strconv.ParseInt(line[14:], 10, 64) | ||
repoSize.SizeGarbage = number * 1024 | ||
} | ||
} | ||
return repoSize | ||
} | ||
|
||
// GetLatestCommitTime returns time for latest commit in repository (across all branches) | ||
func GetLatestCommitTime(ctx context.Context, repoPath string) (time.Time, error) { | ||
cmd := NewCommand(ctx, "for-each-ref", "--sort=-committerdate", BranchPrefix, "--count", "1", "--format=%(committerdate)") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this option even needed? I mean if by default global limit and individual repo limit is 0 (no limit). What is the use case for this option and why disabled by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lafriks The reason why disabled by default is that it is a feature that should be enabled by administrator people mostly install gitea for their own need and such option might not be needed by default. It would be needed for any cloud install. So this allows gitea to work like before.
Despite me believing it that feature is ready, I still believe it should be "experimental" hence disabled by default for some time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lafriks As for the use case it allows to easily switch on and off without modifying anything in the actual limits. Cause it could be quite hard after populating all the size limits individually on different repos to disable this feature. One would need to update each repo size limit to 0 (if he chooses not to use the global one) and his previous value would be lost. The repo size limit takes precedence over global size limit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but if you do not need limits you would not just set them, we have too many options already imho in app ini to add even more, as for being experimental we could state it in docs and UI in label for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from your point of view how this one is close to the needed @lafriks ?
#22900
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lafriks ok so let's see how can we help @a1012112796 to achieve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lafriks that was my use case:
What could the solution be then to achieve it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lafriks is current apporach ok? Can I resolve this. if not - could you choose among the options or suggest something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think we don't need this. We can use
REPO_SIZE_LIMIT = 0
to do the same thing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using the REPO_SIZE_LIMIT = -1 as the switch off (and removing the boolean flag).
REPO_SIZE_LIMIT = 0 Size limit is enabled but I don't care what the size limit is if an individual repo size limit is set use it.
REPO_SIZE_LIMIT > 0 Use this Size limit for any repository where size limit is 0 (not set) use individual repo size where it is set
Does this look acceptable? This would remove the need to for the extra config parameter also it would still allow ti switch off the size limit checking if administrator chooses to do so?