From 1f9fb16844034baf4121bf35c49f2d7466537f20 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 17 Sep 2025 09:58:16 +0200 Subject: [PATCH] deploy: find rclone.conf in the root of the repo This enables the same way of managing the config as existed with s3cmd's s3cfg file. --- fdroidserver/deploy.py | 8 ++++++++ tests/test_deploy.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/fdroidserver/deploy.py b/fdroidserver/deploy.py index a1fe42c3..abaab805 100644 --- a/fdroidserver/deploy.py +++ b/fdroidserver/deploy.py @@ -49,6 +49,8 @@ BINARY_TRANSPARENCY_DIR = 'binary_transparency' REMOTE_HOSTNAME_REGEX = re.compile(r'\W*\w+\W+(\w+).*') +EMBEDDED_RCLONE_CONF = 'rclone.conf' + def _get_index_file_paths(base_dir): """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 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)) @@ -148,6 +153,9 @@ def update_remote_storage_with_rclone( ) sys.exit(1) configfilename = path + elif os.path.exists(EMBEDDED_RCLONE_CONF): + path = EMBEDDED_RCLONE_CONF # in this case, only for display + configfilename = EMBEDDED_RCLONE_CONF else: configfilename = None output = subprocess.check_output(['rclone', 'config', 'file'], text=True) diff --git a/tests/test_deploy.py b/tests/test_deploy.py index c263ef2d..d7de7545 100755 --- a/tests/test_deploy.py +++ b/tests/test_deploy.py @@ -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): """rsync works with file paths, so this test uses paths for the URLs""" os.chdir(self.testdir)