mirror of
				https://github.com/f-droid/fdroidserver.git
				synced 2025-11-04 06:30:27 +03:00 
			
		
		
		
	💂 implement vagrant push
This commit is contained in:
		
							parent
							
								
									9fa7193620
								
							
						
					
					
						commit
						e6e788e533
					
				
					 2 changed files with 59 additions and 1 deletions
				
			
		| 
						 | 
					@ -5213,3 +5213,43 @@ def vagrant_destroy(appid, vercode):
 | 
				
			||||||
        v.destroy()
 | 
					        v.destroy()
 | 
				
			||||||
    if vagrantfile.parent.exists():
 | 
					    if vagrantfile.parent.exists():
 | 
				
			||||||
        shutil.rmtree(vagrantfile.parent, ignore_errors=True)
 | 
					        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()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,6 +32,7 @@ Since this is an internal command, the strings are not localized.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import tarfile
 | 
					import tarfile
 | 
				
			||||||
import tempfile
 | 
					import tempfile
 | 
				
			||||||
| 
						 | 
					@ -99,7 +100,24 @@ def podman_push(paths, appid, vercode, as_root=False):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def vagrant_push(paths, appid, vercode):
 | 
					def vagrant_push(paths, appid, vercode):
 | 
				
			||||||
    """Push files into a build specific vagrant VM."""
 | 
					    """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
 | 
					# TODO split out shared code into _podman.py, _vagrant.py, etc
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue