mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-20 13:50:12 +01:00
git_mirror_size_limit config option to set max git mirror size
GitHub and GitLab have some kinds of limits on how big a git repo can be, this makes that option configurable. This also is very useful for tests.
This commit is contained in:
parent
4fa11ef4fc
commit
e76a0c9d6a
@ -190,6 +190,13 @@ The repository of older versions of applications from the main demo repository.
|
|||||||
# 'https://gitlab.com/user/repo',
|
# 'https://gitlab.com/user/repo',
|
||||||
# }
|
# }
|
||||||
|
|
||||||
|
# Most git hosting services have hard size limits for each git repo.
|
||||||
|
# `fdroid deploy` will delete the git history when the git mirror repo
|
||||||
|
# approaches this limit to ensure that the repo will still fit when
|
||||||
|
# pushed. GitHub recommends 1GB, gitlab.com recommends 10GB.
|
||||||
|
#
|
||||||
|
# git_mirror_size_limit = '10GB'
|
||||||
|
|
||||||
# Any mirrors of this repo, for example all of the servers declared in
|
# Any mirrors of this repo, for example all of the servers declared in
|
||||||
# serverwebroot and all the servers declared in servergitmirrors,
|
# serverwebroot and all the servers declared in servergitmirrors,
|
||||||
# will automatically be used by the client. If one
|
# will automatically be used by the client. If one
|
||||||
|
@ -148,6 +148,7 @@ default_config = {
|
|||||||
'archive_description': _('These are the apps that have been archived from the main repo.'),
|
'archive_description': _('These are the apps that have been archived from the main repo.'),
|
||||||
'archive_older': 0,
|
'archive_older': 0,
|
||||||
'lint_licenses': fdroidserver.lint.APPROVED_LICENSES,
|
'lint_licenses': fdroidserver.lint.APPROVED_LICENSES,
|
||||||
|
'git_mirror_size_limit': 10000000000,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -354,9 +355,31 @@ def read_config(opts, config_file='config.py'):
|
|||||||
raise TypeError(_('only accepts strings, lists, and tuples'))
|
raise TypeError(_('only accepts strings, lists, and tuples'))
|
||||||
config['servergitmirrors'] = roots
|
config['servergitmirrors'] = roots
|
||||||
|
|
||||||
|
limit = config['git_mirror_size_limit']
|
||||||
|
config['git_mirror_size_limit'] = parse_human_readable_size(limit)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
def parse_human_readable_size(size):
|
||||||
|
units = {
|
||||||
|
'b': 1,
|
||||||
|
'kb': 1000, 'mb': 1000**2, 'gb': 1000**3, 'tb': 1000**4,
|
||||||
|
'kib': 1024, 'mib': 1024**2, 'gib': 1024**3, 'tib': 1024**4,
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
return int(float(size))
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
if type(size) != str:
|
||||||
|
raise ValueError(_('Could not parse size "{size}", wrong type "{type}"')
|
||||||
|
.format(size=size, type=type(size)))
|
||||||
|
s = size.lower().replace(' ', '')
|
||||||
|
m = re.match(r'^(?P<value>[0-9][0-9.]+) *(?P<unit>' + r'|'.join(units.keys()) + r')$', s)
|
||||||
|
if not m:
|
||||||
|
raise ValueError(_('Not a valid size definition: "{}"').format(size))
|
||||||
|
return int(float(m.group("value")) * units[m.group("unit")])
|
||||||
|
|
||||||
|
|
||||||
def assert_config_keystore(config):
|
def assert_config_keystore(config):
|
||||||
"""Check weather keystore is configured correctly and raise exception if not."""
|
"""Check weather keystore is configured correctly and raise exception if not."""
|
||||||
|
|
||||||
|
@ -356,11 +356,15 @@ def update_servergitmirrors(servergitmirrors, repo_section):
|
|||||||
# github/gitlab use bare git repos, so only count the .git folder
|
# github/gitlab use bare git repos, so only count the .git folder
|
||||||
# test: generate giant APKs by including AndroidManifest.xml and and large
|
# test: generate giant APKs by including AndroidManifest.xml and and large
|
||||||
# file from /dev/urandom, then sign it. Then add those to the git repo.
|
# file from /dev/urandom, then sign it. Then add those to the git repo.
|
||||||
if os.path.isdir(dotgit) and _get_size(dotgit) > 1000000000:
|
dotgit_size = _get_size(dotgit)
|
||||||
logging.warning('Deleting git-mirror history, repo is too big (1 gig max)')
|
dotgit_over_limit = dotgit_size > config['git_mirror_size_limit']
|
||||||
|
if os.path.isdir(dotgit) and dotgit_over_limit:
|
||||||
|
logging.warning(_('Deleting git-mirror history, repo is too big ({size} max {limit})')
|
||||||
|
.format(size=dotgit_size, limit=config['git_mirror_size_limit']))
|
||||||
shutil.rmtree(dotgit)
|
shutil.rmtree(dotgit)
|
||||||
if options.no_keep_git_mirror_archive and _get_size(dotgit) > 1000000000:
|
if options.no_keep_git_mirror_archive and dotgit_over_limit:
|
||||||
logging.warning('Deleting archive, repo is too big (1 gig max)')
|
logging.warning(_('Deleting archive, repo is too big ({size} max {limit})')
|
||||||
|
.format(size=dotgit_size, limit=config['git_mirror_size_limit']))
|
||||||
archive_path = os.path.join(git_mirror_path, 'fdroid', 'archive')
|
archive_path = os.path.join(git_mirror_path, 'fdroid', 'archive')
|
||||||
shutil.rmtree(archive_path, ignore_errors=True)
|
shutil.rmtree(archive_path, ignore_errors=True)
|
||||||
|
|
||||||
|
@ -45,6 +45,15 @@ class CommonTest(unittest.TestCase):
|
|||||||
os.makedirs(self.tmpdir)
|
os.makedirs(self.tmpdir)
|
||||||
os.chdir(self.basedir)
|
os.chdir(self.basedir)
|
||||||
|
|
||||||
|
def test_parse_human_readable_size(self):
|
||||||
|
for k, v in ((9827, 9827), (123.456, 123), ('123b', 123), ('1.2', 1),
|
||||||
|
('10.43 KiB', 10680), ('11GB', 11000000000), ('59kb', 59000),
|
||||||
|
('343.1 mb', 343100000), ('99.9GiB', 107266808217)):
|
||||||
|
self.assertEqual(fdroidserver.common.parse_human_readable_size(k), v)
|
||||||
|
for v in ((12, 123), '0xfff', [], None, '12,123', '123GG', '982374bb', self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
fdroidserver.common.parse_human_readable_size(v)
|
||||||
|
|
||||||
def test_assert_config_keystore(self):
|
def test_assert_config_keystore(self):
|
||||||
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
|
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
|
||||||
with self.assertRaises(FDroidException):
|
with self.assertRaises(FDroidException):
|
||||||
|
@ -1096,6 +1096,59 @@ $fdroid update --create-key
|
|||||||
test -e $KEYSTORE
|
test -e $KEYSTORE
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------#
|
||||||
|
echo_header "setup a new repo from scratch using ANDROID_HOME with git mirror"
|
||||||
|
|
||||||
|
# fake git remote server for repo mirror
|
||||||
|
SERVER_GIT_MIRROR=`create_test_dir`
|
||||||
|
cd $SERVER_GIT_MIRROR
|
||||||
|
git init
|
||||||
|
git config receive.denyCurrentBranch updateInstead
|
||||||
|
|
||||||
|
REPOROOT=`create_test_dir`
|
||||||
|
GIT_MIRROR=$REPOROOT/git-mirror
|
||||||
|
cd $REPOROOT
|
||||||
|
fdroid_init_with_prebuilt_keystore
|
||||||
|
echo "servergitmirrors = '$SERVER_GIT_MIRROR'" >> config.py
|
||||||
|
|
||||||
|
cp $WORKSPACE/tests/repo/com.politedroid_[345].apk repo/
|
||||||
|
$fdroid update --create-metadata
|
||||||
|
$fdroid deploy
|
||||||
|
test -e $GIT_MIRROR/fdroid/repo/com.politedroid_3.apk
|
||||||
|
test -e $GIT_MIRROR/fdroid/repo/com.politedroid_4.apk
|
||||||
|
test -e $GIT_MIRROR/fdroid/repo/com.politedroid_5.apk
|
||||||
|
test -e $SERVER_GIT_MIRROR/fdroid/repo/com.politedroid_3.apk
|
||||||
|
test -e $SERVER_GIT_MIRROR/fdroid/repo/com.politedroid_4.apk
|
||||||
|
test -e $SERVER_GIT_MIRROR/fdroid/repo/com.politedroid_5.apk
|
||||||
|
date > $GIT_MIRROR/.git/test-stamp
|
||||||
|
|
||||||
|
# add one more APK to trigger archiving
|
||||||
|
cp $WORKSPACE/tests/repo/com.politedroid_6.apk repo/
|
||||||
|
$fdroid update
|
||||||
|
$fdroid deploy
|
||||||
|
test -e $REPOROOT/archive/com.politedroid_3.apk
|
||||||
|
! test -e $GIT_MIRROR/fdroid/archive/com.politedroid_3.apk
|
||||||
|
! test -e $SERVER_GIT_MIRROR/fdroid/archive/com.politedroid_3.apk
|
||||||
|
test -e $GIT_MIRROR/fdroid/repo/com.politedroid_4.apk
|
||||||
|
test -e $GIT_MIRROR/fdroid/repo/com.politedroid_5.apk
|
||||||
|
test -e $GIT_MIRROR/fdroid/repo/com.politedroid_6.apk
|
||||||
|
test -e $SERVER_GIT_MIRROR/fdroid/repo/com.politedroid_4.apk
|
||||||
|
test -e $SERVER_GIT_MIRROR/fdroid/repo/com.politedroid_5.apk
|
||||||
|
test -e $SERVER_GIT_MIRROR/fdroid/repo/com.politedroid_6.apk
|
||||||
|
before=`du -s --bytes $GIT_MIRROR/.git/ | awk '{print $1}'`
|
||||||
|
|
||||||
|
echo "git_mirror_size_limit = '60kb'" >> config.py
|
||||||
|
$fdroid update
|
||||||
|
$fdroid deploy
|
||||||
|
test -e $REPOROOT/archive/com.politedroid_3.apk
|
||||||
|
! test -e $SERVER_GIT_MIRROR/fdroid/archive/com.politedroid_3.apk
|
||||||
|
after=`du -s --bytes $GIT_MIRROR/.git/ | awk '{print $1}'`
|
||||||
|
! test -e $GIT_MIRROR/.git/test-stamp
|
||||||
|
git -C $GIT_MIRROR gc
|
||||||
|
git -C $SERVER_GIT_MIRROR gc
|
||||||
|
test $before -gt $after
|
||||||
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------------#
|
#------------------------------------------------------------------------------#
|
||||||
echo_header "sign binary repo in offline box, then publishing from online box"
|
echo_header "sign binary repo in offline box, then publishing from online box"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user