From e6e788e533f5d31e8b750769012154a469d5c617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Wed, 8 Oct 2025 19:07:32 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=82=20implement=20vagrant=20push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fdroidserver/common.py | 40 ++++++++++++++++++++++++++++++++++++++++ fdroidserver/push.py | 20 +++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 25053d72..97fc1f50 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -5213,3 +5213,43 @@ def vagrant_destroy(appid, vercode): v.destroy() if vagrantfile.parent.exists(): shutil.rmtree(vagrantfile.parent, ignore_errors=True) + + +def get_vagrant_bin_path(): + p = shutil.which("vagrant") + if p is None: + raise Exception( + "'vagrant' not found, make sure it's installed and added to your path" + ) + return p + + +def get_rsync_bin_path(): + p = shutil.which("rsync") + if p is None: + raise Exception( + "'rsync' not found, make sure it's installed and added to your path" + ) + return p + + +class TmpVagrantSshConf: + """Context manager for getting access to a ssh config of a vagrant VM in form of a temp file.""" + + def __init__(self, vagrant_bin_path, vagrant_vm_dir): + self.vagrant_bin_path = vagrant_bin_path + self.vagrant_vm_dir = vagrant_vm_dir + + def __enter__(self): + self.ssh_config_tf = tempfile.NamedTemporaryFile('wt', encoding="utf8") + self.ssh_config_tf.write( + subprocess.check_output( + [self.vagrant_bin_path, 'ssh-config'], + cwd=self.vagrant_vm_dir, + ).decode('utf8') + ) + self.ssh_config_tf.flush() + return self.ssh_config_tf.name + + def __exit__(self, exc_type, exc_value, traceback): + self.ssh_config_tf.close() diff --git a/fdroidserver/push.py b/fdroidserver/push.py index 1719936f..45e78a35 100644 --- a/fdroidserver/push.py +++ b/fdroidserver/push.py @@ -32,6 +32,7 @@ Since this is an internal command, the strings are not localized. import logging import os +import subprocess import sys import tarfile import tempfile @@ -99,7 +100,24 @@ def podman_push(paths, appid, vercode, as_root=False): def vagrant_push(paths, appid, vercode): """Push files into a build specific vagrant VM.""" - # TODO implement with `vagrant ssh` and rsync? + vagrantbin = common.get_vagrant_bin_path() + rsyncbin = common.get_rsync_bin_path() + + vagrantfile = common.get_vagrantfile_path(appid, vercode) + with common.TmpVagrantSshConf(vagrantbin, vagrantfile.parent) as ssh_config_file: + for path in paths: + cmd = [ + rsyncbin, + '-av', + '--relative', + '-e', + f'ssh -F {ssh_config_file}', + path, + 'default:{}'.format(common.BUILD_HOME), + ] + subprocess.check_call( + cmd, + ) # TODO split out shared code into _podman.py, _vagrant.py, etc