Skip to content

Commit

Permalink
buildserver: move config to buildserver/Vagrantfile.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
eighthave committed Nov 3, 2022
1 parent e2fcd63 commit abf535a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 40 deletions.
26 changes: 16 additions & 10 deletions buildserver/Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
require 'yaml'
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
configpath = File.join(srvpath, "/Vagrantfile.yaml")
if File.exists? configpath
configfile = YAML.load_file(configpath)
else
puts "#{configpath} does not exist, run ./makebuildserver?"
configfile = Hash.new
YAML.load_file(configpath).each do |k,v|
configfile[k] = v
end
end

Vagrant.configure("2") do |config|
Expand Down Expand Up @@ -62,12 +71,9 @@ Vagrant.configure("2") do |config|
args: [configfile["aptproxy"]]
end

# buildserver/ is shared to the VM's /vagrant by default so the old
# default does not need a custom mount
if configfile["cachedir"] != "buildserver/cache"
config.vm.synced_folder configfile["cachedir"], '/vagrant/cache',
create: true, type: synced_folder_type
end
config.vm.synced_folder configfile["cachedir"], '/vagrant/cache',
create: true, type: synced_folder_type

# Make sure dir exists to mount to, since buildserver/ is
# automatically mounted as /vagrant in the guest VM. This is more
# necessary with 9p synced folders
Expand Down
10 changes: 5 additions & 5 deletions jenkins-setup-build-environment
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ if [ `nproc` -le 6 ]; then
else
cpus=6
fi
cat <<EOF > $WORKSPACE/makebuildserver.config.py
debian_mirror = 'http://deb.debian.org/debian/'
boot_timeout = 1200
memory = $memory
cpus = $cpus
cat <<EOF > $WORKSPACE/buildserver/Vagrantfile.yaml
debian_mirror: https://deb.debian.org/debian/
boot_timeout: 1200
memory: $memory
cpus: $cpus
EOF

cd $WORKSPACE
Expand Down
48 changes: 23 additions & 25 deletions makebuildserver
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,34 @@ BASEBOX_CHECKSUMS = {
},
}

config = {
'debian_mirror': 'https://deb.debian.org/debian/',
'boot_timeout': 600,
'cachedir': os.path.join(os.getenv('HOME'), '.cache', 'fdroidserver'),
'cpus': 1,
'memory': 2048,
'hwvirtex': 'off',
'vm_provider': 'virtualbox',
}

configfile = 'buildserver/Vagrantfile.yaml'
if not os.path.exists(configfile):
logging.warning('%s does not exist, copying template file.' % configfile)
shutil.copy('examples/Vagrantfile.yaml', configfile)
with open(configfile) as fp:
config = yaml.safe_load(fp)
with open('buildserver/Vagrantfile') as fp:
m = re.search(r"""\.vm\.box\s*=\s*["'](.*)["']""", fp.read())
if not m:
logging.error('Cannot find box name in buildserver/Vagrantfile!')
exit(1)
config['basebox'] = m.group(1)
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'):
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'):
show_config_deprecation = True
# this is the old name for the config file
exec(compile(open('makebs.config.py').read(), 'makebs.config.py', 'exec'), config)
if '__builtins__' in config:
del config['__builtins__'] # added by compile/exec
logging.error('makebs.config.py exists!')
if show_config_deprecation:
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))

# Update cached files.
Expand Down Expand Up @@ -253,17 +256,14 @@ def main():
# use VirtualBox software virtualization if hardware is not available,
# like if this is being run in kvm or some other VM platform, like
# http://jenkins.debian.net, the values are 'on' or 'off'
if sys.platform.startswith('darwin'):
# 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'):
if config.get('hwvirtex') != 'off' and os.path.exists('/proc/cpuinfo'):
with open('/proc/cpuinfo') as f:
contents = f.read()
if 'vmx' in contents or 'svm' in contents:
config['hwvirtex'] = 'on'
logging.info('found \'vmx\' or \'svm\' in /proc/cpuinfo -> hwvirtex = \'on\'')
logging.debug('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')
logfilename = os.path.join(serverdir, 'up.log')
Expand Down Expand Up @@ -351,8 +351,6 @@ def main():
.format(box=config['basebox'],
provider=config['vm_provider'],
version=config['basebox_version']))
else:
logging.debug('not updating basebox ...')
else:
logging.debug('using unverified basebox ...')

Expand Down

0 comments on commit abf535a

Please sign in to comment.