2016-07-04 20:49:41 +02:00
|
|
|
require 'yaml'
|
2017-03-25 23:50:10 +01:00
|
|
|
require 'pathname'
|
2022-10-20 18:24:13 +02:00
|
|
|
require 'fileutils'
|
2017-03-25 23:50:10 +01:00
|
|
|
|
2022-10-19 11:31:38 +02:00
|
|
|
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',
|
|
|
|
}
|
|
|
|
|
2017-03-25 23:50:10 +01:00
|
|
|
srvpath = Pathname.new(File.dirname(__FILE__)).realpath
|
2022-05-18 21:20:25 +02:00
|
|
|
configpath = File.join(srvpath, "/Vagrantfile.yaml")
|
|
|
|
if File.exists? configpath
|
2022-10-20 18:24:13 +02:00
|
|
|
c = YAML.load_file(configpath)
|
|
|
|
if c and not c.empty?
|
|
|
|
c.each do |k,v|
|
|
|
|
configfile[k] = v
|
|
|
|
end
|
2022-10-19 11:31:38 +02:00
|
|
|
end
|
2022-10-20 18:24:13 +02:00
|
|
|
else
|
|
|
|
puts "Copying example file to #{configpath}"
|
|
|
|
FileUtils.cp('../examples/Vagrantfile.yaml', configpath)
|
2022-05-18 21:20:25 +02:00
|
|
|
end
|
2016-07-04 20:49:41 +02:00
|
|
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
|
2022-10-19 10:30:13 +02:00
|
|
|
if Vagrant.has_plugin?("vagrant-cachier")
|
2016-07-04 20:49:41 +02:00
|
|
|
config.cache.scope = :box
|
|
|
|
config.cache.auto_detect = false
|
|
|
|
config.cache.enable :apt
|
|
|
|
config.cache.enable :chef
|
|
|
|
end
|
|
|
|
|
2023-07-27 09:39:11 +02:00
|
|
|
config.vm.box = "debian/bookworm64"
|
2016-07-04 20:49:41 +02:00
|
|
|
|
2016-09-28 09:52:00 +02:00
|
|
|
if not configfile.has_key? "vm_provider" or configfile["vm_provider"] == "virtualbox"
|
|
|
|
# default to VirtualBox if not set
|
|
|
|
config.vm.provider "virtualbox" do |v|
|
|
|
|
v.customize ["modifyvm", :id, "--memory", configfile['memory']]
|
|
|
|
v.customize ["modifyvm", :id, "--cpus", configfile['cpus']]
|
|
|
|
v.customize ["modifyvm", :id, "--hwvirtex", configfile['hwvirtex']]
|
|
|
|
end
|
|
|
|
synced_folder_type = 'virtualbox'
|
|
|
|
elsif configfile["vm_provider"] == "libvirt"
|
2016-09-05 23:21:24 +02:00
|
|
|
# use KVM/QEMU if this is running in KVM/QEMU
|
|
|
|
config.vm.provider :libvirt do |libvirt|
|
2017-06-02 11:35:46 +02:00
|
|
|
libvirt.driver = configfile["hwvirtex"] == "on" ? "kvm" : "qemu"
|
2016-09-05 23:21:24 +02:00
|
|
|
libvirt.host = "localhost"
|
|
|
|
libvirt.uri = "qemu:///system"
|
|
|
|
libvirt.cpus = configfile["cpus"]
|
|
|
|
libvirt.memory = configfile["memory"]
|
2023-07-27 09:39:11 +02:00
|
|
|
# Debian Vagrant image is only 20G, so allocate more
|
|
|
|
libvirt.machine_virtual_size = 1024
|
2018-10-11 12:11:15 +02:00
|
|
|
if configfile.has_key? "libvirt_disk_bus"
|
|
|
|
libvirt.disk_bus = configfile["libvirt_disk_bus"]
|
|
|
|
end
|
|
|
|
if configfile.has_key? "libvirt_nic_model_type"
|
|
|
|
libvirt.nic_model_type = configfile["libvirt_nic_model_type"]
|
|
|
|
end
|
2016-09-05 23:21:24 +02:00
|
|
|
end
|
2019-01-10 14:48:29 +01:00
|
|
|
if configfile.has_key? "synced_folder_type"
|
|
|
|
synced_folder_type = configfile["synced_folder_type"]
|
|
|
|
else
|
|
|
|
synced_folder_type = '9p'
|
|
|
|
end
|
2021-03-18 08:22:57 +01:00
|
|
|
config.vm.synced_folder './', '/vagrant', type: synced_folder_type,
|
|
|
|
SharedFoldersEnableSymlinksCreate: false
|
2016-09-05 23:21:24 +02:00
|
|
|
else
|
|
|
|
abort("No supported VM Provider found, set vm_provider in Vagrantfile.yaml!")
|
2016-07-04 20:49:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
config.vm.boot_timeout = configfile['boot_timeout']
|
|
|
|
|
|
|
|
if configfile.has_key? "aptproxy"
|
|
|
|
config.vm.provision :shell, path: "provision-apt-proxy",
|
|
|
|
args: [configfile["aptproxy"]]
|
|
|
|
end
|
|
|
|
|
2022-10-19 11:31:38 +02:00
|
|
|
config.vm.synced_folder configfile["cachedir"], '/vagrant/cache',
|
|
|
|
create: true, type: synced_folder_type
|
|
|
|
|
2016-09-15 15:50:16 +02:00
|
|
|
# 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
|
|
|
|
Dir.mkdir('cache') unless File.exists?('cache')
|
2016-07-04 20:49:41 +02:00
|
|
|
|
2023-07-27 09:39:11 +02:00
|
|
|
# Root partition needs to be resized to the new allocated space
|
|
|
|
config.vm.provision "shell", inline: <<-SHELL
|
|
|
|
growpart -v -u auto /dev/vda 1
|
|
|
|
resize2fs /dev/vda1
|
|
|
|
SHELL
|
|
|
|
|
2021-12-23 21:39:29 +01:00
|
|
|
config.vm.provision "shell", name: "setup-env-vars", path: "setup-env-vars",
|
2021-05-25 17:30:20 +02:00
|
|
|
args: ["/opt/android-sdk"]
|
2021-12-23 21:39:29 +01:00
|
|
|
config.vm.provision "shell", name: "apt-get-install", path: "provision-apt-get-install",
|
2016-07-04 20:49:41 +02:00
|
|
|
args: [configfile['debian_mirror']]
|
2021-12-23 21:39:29 +01:00
|
|
|
config.vm.provision "shell", name: "android-sdk", path: "provision-android-sdk"
|
|
|
|
config.vm.provision "shell", name: "android-ndk", path: "provision-android-ndk",
|
2022-10-14 21:46:50 +02:00
|
|
|
args: ["/opt/android-sdk/ndk"]
|
2021-12-23 21:39:29 +01:00
|
|
|
config.vm.provision "shell", name: "gradle", path: "provision-gradle"
|
2022-04-21 15:36:03 +02:00
|
|
|
config.vm.provision "shell", name: "disable-analytics", path: "provision-disable-analytics"
|
2021-12-23 21:39:29 +01:00
|
|
|
config.vm.provision "shell", name: "buildserverid", path: "provision-buildserverid",
|
2021-12-15 14:43:14 +01:00
|
|
|
args: [`git rev-parse HEAD`]
|
2016-07-04 20:49:41 +02:00
|
|
|
|
|
|
|
end
|