Merge branch 'user-rclone.conf' into 'master'

deploy: find rclone.conf in the root of the repo

See merge request fdroid/fdroidserver!1701
This commit is contained in:
Hans-Christoph Steiner 2025-09-18 10:01:04 +00:00
commit c9c5147cac
2 changed files with 43 additions and 0 deletions

View file

@ -49,6 +49,8 @@ BINARY_TRANSPARENCY_DIR = 'binary_transparency'
REMOTE_HOSTNAME_REGEX = re.compile(r'\W*\w+\W+(\w+).*') REMOTE_HOSTNAME_REGEX = re.compile(r'\W*\w+\W+(\w+).*')
EMBEDDED_RCLONE_CONF = 'rclone.conf'
def _get_index_file_paths(base_dir): def _get_index_file_paths(base_dir):
"""Return the list of files to be synced last, since they finalize the deploy. """Return the list of files to be synced last, since they finalize the deploy.
@ -131,6 +133,9 @@ def update_remote_storage_with_rclone(
"--include" implies "--exclude **" at the end of an rclone internal "--include" implies "--exclude **" at the end of an rclone internal
filter list. filter list.
If rclone.conf is in the root of the repo, then it will be preferred
over the rclone default config paths.
""" """
logging.debug(_('Using rclone to sync to "{name}"').format(name=awsbucket)) logging.debug(_('Using rclone to sync to "{name}"').format(name=awsbucket))
@ -148,6 +153,11 @@ def update_remote_storage_with_rclone(
) )
sys.exit(1) sys.exit(1)
configfilename = path configfilename = path
elif os.path.exists(EMBEDDED_RCLONE_CONF):
path = EMBEDDED_RCLONE_CONF # in this case, only for display
configfilename = EMBEDDED_RCLONE_CONF
if not rclone_config:
raise FDroidException(_("'rclone_config' must be set in config.yml!"))
else: else:
configfilename = None configfilename = None
output = subprocess.check_output(['rclone', 'config', 'file'], text=True) output = subprocess.check_output(['rclone', 'config', 'file'], text=True)

View file

@ -288,6 +288,39 @@ class DeployTest(unittest.TestCase):
], ],
) )
@mock.patch('subprocess.check_output', _mock_rclone_config_file)
@mock.patch('subprocess.call')
def test_update_remote_storage_with_rclone_mock_default_user_path(self, mock_call):
self.last_cmd = None
def _mock_subprocess_call(cmd):
self.last_cmd = cmd
return 0
mock_call.side_effect = _mock_subprocess_call
os.chdir(self.testdir)
config_name = 'test_local_config'
Path('rclone.conf').write_text('placeholder, contents ignored')
awsbucket = 'test_bucket_folder'
fdroidserver.deploy.config['awsbucket'] = awsbucket
fdroidserver.deploy.config['rclone_config'] = config_name
fdroidserver.deploy.update_remote_storage_with_rclone('repo', awsbucket)
self.maxDiff = None
self.assertEqual(
self.last_cmd,
[
'rclone',
'sync',
'--delete-after',
'--config',
fdroidserver.deploy.EMBEDDED_RCLONE_CONF,
'repo',
f'{config_name}:{awsbucket}/fdroid/repo',
],
)
def test_update_serverwebroot(self): def test_update_serverwebroot(self):
"""rsync works with file paths, so this test uses paths for the URLs""" """rsync works with file paths, so this test uses paths for the URLs"""
os.chdir(self.testdir) os.chdir(self.testdir)