mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 15:13:27 +02:00
config: convert serverwebroot: to list-of-dicts format
This allows for more metadata about the server and deploy mode.
This commit is contained in:
parent
3f50372d8d
commit
7a656d45e3
@ -178,6 +178,12 @@
|
|||||||
# serverwebroot:
|
# serverwebroot:
|
||||||
# - foo.com:/usr/share/nginx/www/fdroid
|
# - foo.com:/usr/share/nginx/www/fdroid
|
||||||
# - bar.info:/var/www/fdroid
|
# - bar.info:/var/www/fdroid
|
||||||
|
#
|
||||||
|
# There is a special mode to only deploy the index file:
|
||||||
|
#
|
||||||
|
# serverwebroot:
|
||||||
|
# - url: 'me@b.az:/srv/fdroid'
|
||||||
|
# indexOnly: true
|
||||||
|
|
||||||
|
|
||||||
# When running fdroid processes on a remote server, it is possible to
|
# When running fdroid processes on a remote server, it is possible to
|
||||||
|
@ -462,18 +462,22 @@ def read_config(opts=None):
|
|||||||
|
|
||||||
if 'serverwebroot' in config:
|
if 'serverwebroot' in config:
|
||||||
if isinstance(config['serverwebroot'], str):
|
if isinstance(config['serverwebroot'], str):
|
||||||
roots = [config['serverwebroot']]
|
roots = [{'url': config['serverwebroot']}]
|
||||||
elif all(isinstance(item, str) for item in config['serverwebroot']):
|
elif all(isinstance(item, str) for item in config['serverwebroot']):
|
||||||
|
roots = [{'url': i} for i in config['serverwebroot']]
|
||||||
|
elif all(isinstance(item, dict) for item in config['serverwebroot']):
|
||||||
roots = config['serverwebroot']
|
roots = config['serverwebroot']
|
||||||
else:
|
else:
|
||||||
raise TypeError(_('only accepts strings, lists, and tuples'))
|
raise TypeError(_('only accepts strings, lists, and tuples'))
|
||||||
rootlist = []
|
rootlist = []
|
||||||
for rootstr in roots:
|
for d in roots:
|
||||||
# since this is used with rsync, where trailing slashes have
|
# since this is used with rsync, where trailing slashes have
|
||||||
# meaning, ensure there is always a trailing slash
|
# meaning, ensure there is always a trailing slash
|
||||||
|
rootstr = d['url']
|
||||||
if rootstr[-1] != '/':
|
if rootstr[-1] != '/':
|
||||||
rootstr += '/'
|
rootstr += '/'
|
||||||
rootlist.append(rootstr.replace('//', '/'))
|
d['url'] = rootstr.replace('//', '/')
|
||||||
|
rootlist.append(d)
|
||||||
config['serverwebroot'] = rootlist
|
config['serverwebroot'] = rootlist
|
||||||
|
|
||||||
if 'servergitmirrors' in config:
|
if 'servergitmirrors' in config:
|
||||||
@ -4052,7 +4056,8 @@ def rsync_status_file_to_repo(path, repo_subdir=None):
|
|||||||
logging.debug(_('skip deploying full build logs: not enabled in config'))
|
logging.debug(_('skip deploying full build logs: not enabled in config'))
|
||||||
return
|
return
|
||||||
|
|
||||||
for webroot in config.get('serverwebroot', []):
|
for d in config.get('serverwebroot', []):
|
||||||
|
webroot = d['url']
|
||||||
cmd = ['rsync',
|
cmd = ['rsync',
|
||||||
'--archive',
|
'--archive',
|
||||||
'--delete-after',
|
'--delete-after',
|
||||||
|
@ -294,11 +294,12 @@ def update_serverwebroot(serverwebroot, repo_section):
|
|||||||
rsyncargs += ['-e', 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' + options.identity_file]
|
rsyncargs += ['-e', 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' + options.identity_file]
|
||||||
elif 'identity_file' in config:
|
elif 'identity_file' in config:
|
||||||
rsyncargs += ['-e', 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' + config['identity_file']]
|
rsyncargs += ['-e', 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' + config['identity_file']]
|
||||||
logging.info('rsyncing ' + repo_section + ' to ' + serverwebroot)
|
url = serverwebroot['url']
|
||||||
|
logging.info('rsyncing ' + repo_section + ' to ' + url)
|
||||||
excludes = _get_index_excludes(repo_section)
|
excludes = _get_index_excludes(repo_section)
|
||||||
if subprocess.call(rsyncargs + excludes + [repo_section, serverwebroot]) != 0:
|
if subprocess.call(rsyncargs + excludes + [repo_section, url]) != 0:
|
||||||
raise FDroidException()
|
raise FDroidException()
|
||||||
if subprocess.call(rsyncargs + [repo_section, serverwebroot]) != 0:
|
if subprocess.call(rsyncargs + [repo_section, url]) != 0:
|
||||||
raise FDroidException()
|
raise FDroidException()
|
||||||
# upload "current version" symlinks if requested
|
# upload "current version" symlinks if requested
|
||||||
if config['make_current_version_link'] and repo_section == 'repo':
|
if config['make_current_version_link'] and repo_section == 'repo':
|
||||||
@ -308,7 +309,7 @@ def update_serverwebroot(serverwebroot, repo_section):
|
|||||||
if os.path.islink(f):
|
if os.path.islink(f):
|
||||||
links_to_upload.append(f)
|
links_to_upload.append(f)
|
||||||
if len(links_to_upload) > 0:
|
if len(links_to_upload) > 0:
|
||||||
if subprocess.call(rsyncargs + links_to_upload + [serverwebroot]) != 0:
|
if subprocess.call(rsyncargs + links_to_upload + [url]) != 0:
|
||||||
raise FDroidException()
|
raise FDroidException()
|
||||||
|
|
||||||
|
|
||||||
|
@ -1655,8 +1655,8 @@ class CommonTest(unittest.TestCase):
|
|||||||
fdroidserver.common.options.quiet = False
|
fdroidserver.common.options.quiet = False
|
||||||
fdroidserver.common.config = {}
|
fdroidserver.common.config = {}
|
||||||
fdroidserver.common.config['serverwebroot'] = [
|
fdroidserver.common.config['serverwebroot'] = [
|
||||||
'example.com:/var/www/fdroid/',
|
{'url': 'example.com:/var/www/fdroid/'},
|
||||||
'example.com:/var/www/fbot/',
|
{'url': 'example.com:/var/www/fbot/'},
|
||||||
]
|
]
|
||||||
fdroidserver.common.config['deploy_process_logs'] = True
|
fdroidserver.common.config['deploy_process_logs'] = True
|
||||||
fdroidserver.common.config['identity_file'] = 'ssh/id_rsa'
|
fdroidserver.common.config['identity_file'] = 'ssh/id_rsa'
|
||||||
@ -1718,7 +1718,7 @@ class CommonTest(unittest.TestCase):
|
|||||||
|
|
||||||
fdroidserver.common.options = mock.Mock()
|
fdroidserver.common.options = mock.Mock()
|
||||||
fdroidserver.common.config = {}
|
fdroidserver.common.config = {}
|
||||||
fdroidserver.common.config['serverwebroot'] = [fakeserver]
|
fdroidserver.common.config['serverwebroot'] = [{'url': fakeserver}]
|
||||||
fdroidserver.common.config['identity_file'] = 'ssh/id_rsa'
|
fdroidserver.common.config['identity_file'] = 'ssh/id_rsa'
|
||||||
|
|
||||||
def assert_subprocess_call(cmd):
|
def assert_subprocess_call(cmd):
|
||||||
@ -2872,7 +2872,7 @@ class CommonTest(unittest.TestCase):
|
|||||||
os.chdir(self.testdir)
|
os.chdir(self.testdir)
|
||||||
Path('config.yml').write_text("""serverwebroot: 'foo@example.com:/var/www'""")
|
Path('config.yml').write_text("""serverwebroot: 'foo@example.com:/var/www'""")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
['foo@example.com:/var/www/'],
|
[{'url': 'foo@example.com:/var/www/'}],
|
||||||
fdroidserver.common.read_config()['serverwebroot'],
|
fdroidserver.common.read_config()['serverwebroot'],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -2880,7 +2880,15 @@ class CommonTest(unittest.TestCase):
|
|||||||
os.chdir(self.testdir)
|
os.chdir(self.testdir)
|
||||||
Path('config.yml').write_text("""serverwebroot:\n - foo@example.com:/var/www""")
|
Path('config.yml').write_text("""serverwebroot:\n - foo@example.com:/var/www""")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
['foo@example.com:/var/www/'],
|
[{'url': 'foo@example.com:/var/www/'}],
|
||||||
|
fdroidserver.common.read_config()['serverwebroot'],
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_config_serverwebroot_dict(self):
|
||||||
|
os.chdir(self.testdir)
|
||||||
|
Path('config.yml').write_text("""serverwebroot:\n - url: 'foo@example.com:/var/www'""")
|
||||||
|
self.assertEqual(
|
||||||
|
[{'url': 'foo@example.com:/var/www/'}],
|
||||||
fdroidserver.common.read_config()['serverwebroot'],
|
fdroidserver.common.read_config()['serverwebroot'],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,16 +45,16 @@ class DeployTest(unittest.TestCase):
|
|||||||
fake_apk = repo / 'fake.apk'
|
fake_apk = repo / 'fake.apk'
|
||||||
with fake_apk.open('w') as fp:
|
with fake_apk.open('w') as fp:
|
||||||
fp.write('not an APK, but has the right filename')
|
fp.write('not an APK, but has the right filename')
|
||||||
serverwebroot = Path('serverwebroot')
|
url = Path('url')
|
||||||
serverwebroot.mkdir()
|
url.mkdir()
|
||||||
|
|
||||||
# setup parameters for this test run
|
# setup parameters for this test run
|
||||||
fdroidserver.deploy.options.identity_file = None
|
fdroidserver.deploy.options.identity_file = None
|
||||||
fdroidserver.deploy.config['make_current_version_link'] = False
|
fdroidserver.deploy.config['make_current_version_link'] = False
|
||||||
|
|
||||||
dest_apk = Path(serverwebroot) / fake_apk
|
dest_apk = url / fake_apk
|
||||||
self.assertFalse(dest_apk.is_file())
|
self.assertFalse(dest_apk.is_file())
|
||||||
fdroidserver.deploy.update_serverwebroot(str(serverwebroot), 'repo')
|
fdroidserver.deploy.update_serverwebroot({'url': str(url)}, 'repo')
|
||||||
self.assertTrue(dest_apk.is_file())
|
self.assertTrue(dest_apk.is_file())
|
||||||
|
|
||||||
@mock.patch.dict(os.environ, clear=True)
|
@mock.patch.dict(os.environ, clear=True)
|
||||||
@ -72,7 +72,7 @@ class DeployTest(unittest.TestCase):
|
|||||||
fdroidserver.deploy.options.quiet = True
|
fdroidserver.deploy.options.quiet = True
|
||||||
fdroidserver.deploy.options.identity_file = None
|
fdroidserver.deploy.options.identity_file = None
|
||||||
fdroidserver.deploy.config['make_current_version_link'] = True
|
fdroidserver.deploy.config['make_current_version_link'] = True
|
||||||
serverwebroot = "example.com:/var/www/fdroid"
|
url = "example.com:/var/www/fdroid"
|
||||||
repo_section = 'repo'
|
repo_section = 'repo'
|
||||||
|
|
||||||
# setup function for asserting subprocess.call invocations
|
# setup function for asserting subprocess.call invocations
|
||||||
@ -123,7 +123,7 @@ class DeployTest(unittest.TestCase):
|
|||||||
'--safe-links',
|
'--safe-links',
|
||||||
'--quiet',
|
'--quiet',
|
||||||
'repo',
|
'repo',
|
||||||
serverwebroot,
|
url,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
elif call_iteration == 2:
|
elif call_iteration == 2:
|
||||||
@ -152,7 +152,7 @@ class DeployTest(unittest.TestCase):
|
|||||||
os.symlink('repo/com.example.sym.apk.asc', 'Sym.apk.asc')
|
os.symlink('repo/com.example.sym.apk.asc', 'Sym.apk.asc')
|
||||||
os.symlink('repo/com.example.sym.apk.sig', 'Sym.apk.sig')
|
os.symlink('repo/com.example.sym.apk.sig', 'Sym.apk.sig')
|
||||||
with mock.patch('subprocess.call', side_effect=update_server_webroot_call):
|
with mock.patch('subprocess.call', side_effect=update_server_webroot_call):
|
||||||
fdroidserver.deploy.update_serverwebroot(serverwebroot, repo_section)
|
fdroidserver.deploy.update_serverwebroot({'url': url}, repo_section)
|
||||||
self.assertEqual(call_iteration, 3, 'expected 3 invocations of subprocess.call')
|
self.assertEqual(call_iteration, 3, 'expected 3 invocations of subprocess.call')
|
||||||
|
|
||||||
def test_update_serverwebroot_with_id_file(self):
|
def test_update_serverwebroot_with_id_file(self):
|
||||||
@ -163,7 +163,7 @@ class DeployTest(unittest.TestCase):
|
|||||||
fdroidserver.deploy.options.identity_file = None
|
fdroidserver.deploy.options.identity_file = None
|
||||||
fdroidserver.deploy.config['identity_file'] = './id_rsa'
|
fdroidserver.deploy.config['identity_file'] = './id_rsa'
|
||||||
fdroidserver.deploy.config['make_current_version_link'] = False
|
fdroidserver.deploy.config['make_current_version_link'] = False
|
||||||
serverwebroot = "example.com:/var/www/fdroid"
|
url = "example.com:/var/www/fdroid"
|
||||||
repo_section = 'archive'
|
repo_section = 'archive'
|
||||||
|
|
||||||
# setup function for asserting subprocess.call invocations
|
# setup function for asserting subprocess.call invocations
|
||||||
@ -204,7 +204,7 @@ class DeployTest(unittest.TestCase):
|
|||||||
'--exclude',
|
'--exclude',
|
||||||
'archive/index.xml',
|
'archive/index.xml',
|
||||||
'archive',
|
'archive',
|
||||||
serverwebroot,
|
url,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
elif call_iteration == 1:
|
elif call_iteration == 1:
|
||||||
@ -220,7 +220,7 @@ class DeployTest(unittest.TestCase):
|
|||||||
'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
|
'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
|
||||||
+ fdroidserver.deploy.config['identity_file'],
|
+ fdroidserver.deploy.config['identity_file'],
|
||||||
'archive',
|
'archive',
|
||||||
serverwebroot,
|
url,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -229,7 +229,7 @@ class DeployTest(unittest.TestCase):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
with mock.patch('subprocess.call', side_effect=update_server_webroot_call):
|
with mock.patch('subprocess.call', side_effect=update_server_webroot_call):
|
||||||
fdroidserver.deploy.update_serverwebroot(serverwebroot, repo_section)
|
fdroidserver.deploy.update_serverwebroot({'url': url}, repo_section)
|
||||||
self.assertEqual(call_iteration, 2, 'expected 2 invocations of subprocess.call')
|
self.assertEqual(call_iteration, 2, 'expected 2 invocations of subprocess.call')
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
|
Loading…
Reference in New Issue
Block a user