buildserver: move config to buildserver/Vagrantfile.yaml

This commit is contained in:
Hans-Christoph Steiner 2022-10-19 11:31:38 +02:00
parent e2fcd633fc
commit abf535aabe
No known key found for this signature in database
GPG Key ID: 3E177817BA1B9BFA
3 changed files with 44 additions and 40 deletions

View File

@ -1,13 +1,22 @@
require 'yaml' require 'yaml'
require 'pathname' require 'pathname'
configfile = {
'boot_timeout' => 600,
'cachedir' => File.join(ENV['HOME'], '.cache', 'fdroidserver'),
'cpus' => 1,
'debian_mirror' => 'https://deb.debian.org/debian/',
'hwvirtex' => 'on',
'memory' => 2048,
'vm_provider' => 'virtualbox',
}
srvpath = Pathname.new(File.dirname(__FILE__)).realpath srvpath = Pathname.new(File.dirname(__FILE__)).realpath
configpath = File.join(srvpath, "/Vagrantfile.yaml") configpath = File.join(srvpath, "/Vagrantfile.yaml")
if File.exists? configpath if File.exists? configpath
configfile = YAML.load_file(configpath) YAML.load_file(configpath).each do |k,v|
else configfile[k] = v
puts "#{configpath} does not exist, run ./makebuildserver?" end
configfile = Hash.new
end end
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
@ -62,12 +71,9 @@ Vagrant.configure("2") do |config|
args: [configfile["aptproxy"]] args: [configfile["aptproxy"]]
end end
# buildserver/ is shared to the VM's /vagrant by default so the old config.vm.synced_folder configfile["cachedir"], '/vagrant/cache',
# default does not need a custom mount create: true, type: synced_folder_type
if configfile["cachedir"] != "buildserver/cache"
config.vm.synced_folder configfile["cachedir"], '/vagrant/cache',
create: true, type: synced_folder_type
end
# Make sure dir exists to mount to, since buildserver/ is # Make sure dir exists to mount to, since buildserver/ is
# automatically mounted as /vagrant in the guest VM. This is more # automatically mounted as /vagrant in the guest VM. This is more
# necessary with 9p synced folders # necessary with 9p synced folders

View File

@ -66,11 +66,11 @@ if [ `nproc` -le 6 ]; then
else else
cpus=6 cpus=6
fi fi
cat <<EOF > $WORKSPACE/makebuildserver.config.py cat <<EOF > $WORKSPACE/buildserver/Vagrantfile.yaml
debian_mirror = 'http://deb.debian.org/debian/' debian_mirror: https://deb.debian.org/debian/
boot_timeout = 1200 boot_timeout: 1200
memory = $memory memory: $memory
cpus = $cpus cpus: $cpus
EOF EOF
cd $WORKSPACE cd $WORKSPACE

View File

@ -78,16 +78,12 @@ BASEBOX_CHECKSUMS = {
}, },
} }
config = { configfile = 'buildserver/Vagrantfile.yaml'
'debian_mirror': 'https://deb.debian.org/debian/', if not os.path.exists(configfile):
'boot_timeout': 600, logging.warning('%s does not exist, copying template file.' % configfile)
'cachedir': os.path.join(os.getenv('HOME'), '.cache', 'fdroidserver'), shutil.copy('examples/Vagrantfile.yaml', configfile)
'cpus': 1, with open(configfile) as fp:
'memory': 2048, config = yaml.safe_load(fp)
'hwvirtex': 'off',
'vm_provider': 'virtualbox',
}
with open('buildserver/Vagrantfile') as fp: with open('buildserver/Vagrantfile') as fp:
m = re.search(r"""\.vm\.box\s*=\s*["'](.*)["']""", fp.read()) m = re.search(r"""\.vm\.box\s*=\s*["'](.*)["']""", fp.read())
if not m: if not m:
@ -95,14 +91,21 @@ with open('buildserver/Vagrantfile') as fp:
exit(1) exit(1)
config['basebox'] = m.group(1) config['basebox'] = m.group(1)
config['basebox_version'] = BASEBOX_VERSION_DEFAULT config['basebox_version'] = BASEBOX_VERSION_DEFAULT
# load config file, if present config['cachedir'] = os.path.join(os.getenv('HOME'), '.cache', 'fdroidserver')
show_config_deprecation = False
if os.path.exists('makebuildserver.config.py'): if os.path.exists('makebuildserver.config.py'):
exec(compile(open('makebuildserver.config.py').read(), 'makebuildserver.config.py', 'exec'), config) show_config_deprecation = True
logging.error('makebuildserver.config.py exists!')
elif os.path.exists('makebs.config.py'): elif os.path.exists('makebs.config.py'):
show_config_deprecation = True
# this is the old name for the config file # this is the old name for the config file
exec(compile(open('makebs.config.py').read(), 'makebs.config.py', 'exec'), config) logging.error('makebs.config.py exists!')
if '__builtins__' in config: if show_config_deprecation:
del config['__builtins__'] # added by compile/exec logging.error('Config is via buildserver/Vagrantfile.yaml and command line flags.')
parser.print_help()
exit(1)
logging.debug("makebuildserver.config.py parsed -> %s", json.dumps(config, indent=4, sort_keys=True)) logging.debug("makebuildserver.config.py parsed -> %s", json.dumps(config, indent=4, sort_keys=True))
# Update cached files. # Update cached files.
@ -253,17 +256,14 @@ def main():
# use VirtualBox software virtualization if hardware is not available, # use VirtualBox software virtualization if hardware is not available,
# like if this is being run in kvm or some other VM platform, like # like if this is being run in kvm or some other VM platform, like
# http://jenkins.debian.net, the values are 'on' or 'off' # http://jenkins.debian.net, the values are 'on' or 'off'
if sys.platform.startswith('darwin'): if config.get('hwvirtex') != 'off' and os.path.exists('/proc/cpuinfo'):
# all < 10 year old Macs work, and OSX servers as VM host are very
# rare, but this could also be auto-detected if someone codes it
config['hwvirtex'] = 'on'
logging.info('platform is darwnin -> hwvirtex = \'on\'')
elif os.path.exists('/proc/cpuinfo'):
with open('/proc/cpuinfo') as f: with open('/proc/cpuinfo') as f:
contents = f.read() contents = f.read()
if 'vmx' in contents or 'svm' in contents: if 'vmx' in contents or 'svm' in contents:
config['hwvirtex'] = 'on' logging.debug('found \'vmx\' or \'svm\' in /proc/cpuinfo -> hwvirtex = \'on\'')
logging.info('found \'vmx\' or \'svm\' in /proc/cpuinfo -> hwvirtex = \'on\'') else:
logging.error('hwvirtex = \'on\' and no \'vmx\' or \'svm\' found in /proc/cpuinfo!')
exit(1)
serverdir = os.path.join(os.getcwd(), 'buildserver') serverdir = os.path.join(os.getcwd(), 'buildserver')
logfilename = os.path.join(serverdir, 'up.log') logfilename = os.path.join(serverdir, 'up.log')
@ -351,8 +351,6 @@ def main():
.format(box=config['basebox'], .format(box=config['basebox'],
provider=config['vm_provider'], provider=config['vm_provider'],
version=config['basebox_version'])) version=config['basebox_version']))
else:
logging.debug('not updating basebox ...')
else: else:
logging.debug('using unverified basebox ...') logging.debug('using unverified basebox ...')