Vagrantfile 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # Automated creation of testing environments / binaries on misc. platforms
  4. $cpus = Integer(ENV.fetch('VMCPUS', '16')) # create VMs with that many cpus
  5. $xdistn = Integer(ENV.fetch('XDISTN', '16')) # dispatch tests to that many pytest workers
  6. $wmem = $xdistn * 256 # give the VM additional memory for workers [MB]
  7. def packages_debianoid(user)
  8. return <<-EOF
  9. export DEBIAN_FRONTEND=noninteractive
  10. # This is to avoid GRUB asking which device it should install to:
  11. echo "set grub-pc/install_devices /dev/sda" | debconf-communicate
  12. apt-get -y -qq update
  13. apt-get -y -qq dist-upgrade
  14. # For building BorgBackup and dependencies:
  15. apt install -y libssl-dev libacl1-dev liblz4-dev libzstd-dev libxxhash-dev pkg-config
  16. apt install -y libfuse-dev fuse || true
  17. apt install -y libfuse3-dev fuse3 || true
  18. apt install -y locales || true
  19. # We need to give the prefix to support Debian Buster (no libxxhash.pc for pkg-config there):
  20. echo 'export BORG_LIBXXHASH_PREFIX=/usr' >> ~vagrant/.bash_profile
  21. sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
  22. usermod -a -G fuse #{user}
  23. chgrp fuse /dev/fuse
  24. chmod 666 /dev/fuse
  25. apt install -y fakeroot build-essential git curl
  26. apt install -y python3-dev python3-setuptools virtualenv
  27. # for building python:
  28. apt install -y zlib1g-dev libbz2-dev libncurses5-dev libreadline-dev liblzma-dev libsqlite3-dev libffi-dev
  29. EOF
  30. end
  31. def packages_freebsd
  32. return <<-EOF
  33. # in case the VM has no hostname set
  34. hostname freebsd
  35. # install all the (security and other) updates, base system
  36. freebsd-update --not-running-from-cron fetch install
  37. # For building BorgBackup and dependencies:
  38. pkg install -y liblz4 zstd pkgconf
  39. pkg install -y fusefs-libs || true
  40. pkg install -y fusefs-libs3 || true
  41. pkg install -y rust
  42. pkg install -y git bash # fakeroot causes lots of troubles on freebsd
  43. # for building python (for the tests we use pyenv built pythons):
  44. pkg install -y python310 py310-sqlite3
  45. # make sure there is a python3 command
  46. ln -sf /usr/local/bin/python3.10 /usr/local/bin/python3
  47. python3 -m ensurepip
  48. pip3 install virtualenv
  49. # make bash default / work:
  50. chsh -s bash vagrant
  51. mount -t fdescfs fdesc /dev/fd
  52. echo 'fdesc /dev/fd fdescfs rw 0 0' >> /etc/fstab
  53. # make FUSE work
  54. echo 'fuse_load="YES"' >> /boot/loader.conf
  55. echo 'vfs.usermount=1' >> /etc/sysctl.conf
  56. kldload fusefs
  57. sysctl vfs.usermount=1
  58. pw groupmod operator -M vagrant
  59. # /dev/fuse has group operator
  60. chmod 666 /dev/fuse
  61. # install all the (security and other) updates, packages
  62. pkg update
  63. yes | pkg upgrade
  64. echo 'export BORG_OPENSSL_PREFIX=/usr' >> ~vagrant/.bash_profile
  65. EOF
  66. end
  67. def packages_openbsd
  68. return <<-EOF
  69. hostname "openbsd77.localdomain"
  70. echo "$(hostname)" > /etc/myname
  71. echo "127.0.0.1 localhost" > /etc/hosts
  72. echo "::1 localhost" >> /etc/hosts
  73. echo "127.0.0.1 $(hostname) $(hostname -s)" >> /etc/hosts
  74. echo "https://ftp.eu.openbsd.org/pub/OpenBSD" > /etc/installurl
  75. ftp https://cdn.openbsd.org/pub/OpenBSD/$(uname -r)/$(uname -m)/comp$(uname -r | tr -d .).tgz
  76. tar -C / -xzphf comp$(uname -r | tr -d .).tgz
  77. rm comp$(uname -r | tr -d .).tgz
  78. pkg_add bash
  79. chsh -s bash vagrant
  80. pkg_add xxhash
  81. pkg_add lz4
  82. pkg_add zstd
  83. pkg_add git # no fakeroot
  84. pkg_add rust
  85. pkg_add openssl%3.4
  86. pkg_add py3-pip
  87. pkg_add py3-virtualenv
  88. EOF
  89. end
  90. def packages_netbsd
  91. return <<-EOF
  92. echo 'http://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/$arch/9.3/All' > /usr/pkg/etc/pkgin/repositories.conf
  93. pkgin update
  94. pkgin -y upgrade
  95. pkg_add zstd lz4 xxhash git
  96. pkg_add rust
  97. pkg_add bash
  98. chsh -s bash vagrant
  99. echo "export PROMPT_COMMAND=" >> ~vagrant/.bash_profile # bug in netbsd 9.2, .bash_profile broken for screen
  100. echo "export PROMPT_COMMAND=" >> ~root/.bash_profile # bug in netbsd 9.2, .bash_profile broken for screen
  101. pkg_add pkg-config
  102. # pkg_add fuse # llfuse supports netbsd, but is still buggy.
  103. # https://bitbucket.org/nikratio/python-llfuse/issues/70/perfuse_open-setsockopt-no-buffer-space
  104. pkg_add py311-sqlite3 py311-pip py311-virtualenv py311-expat
  105. ln -s /usr/pkg/bin/python3.11 /usr/pkg/bin/python
  106. ln -s /usr/pkg/bin/python3.11 /usr/pkg/bin/python3
  107. ln -s /usr/pkg/bin/pip3.11 /usr/pkg/bin/pip
  108. ln -s /usr/pkg/bin/pip3.11 /usr/pkg/bin/pip3
  109. ln -s /usr/pkg/bin/virtualenv-3.11 /usr/pkg/bin/virtualenv
  110. ln -s /usr/pkg/bin/virtualenv-3.11 /usr/pkg/bin/virtualenv3
  111. EOF
  112. end
  113. def package_update_openindiana
  114. return <<-EOF
  115. echo "nameserver 1.1.1.1" > /etc/resolv.conf
  116. # needs separate provisioning step + reboot to become effective:
  117. pkg update
  118. EOF
  119. end
  120. def packages_openindiana
  121. return <<-EOF
  122. pkg install gcc-13 git
  123. pkg install pkg-config libxxhash
  124. pkg install python-313
  125. ln -sf /usr/bin/python3.13 /usr/bin/python3
  126. ln -sf /usr/bin/python3.13-config /usr/bin/python3-config
  127. python3 -m ensurepip
  128. ln -sf /usr/bin/pip3.13 /usr/bin/pip3
  129. pip3 install virtualenv
  130. # let borg's pkg-config find openssl:
  131. pfexec pkg set-mediator -V 3 openssl
  132. EOF
  133. end
  134. def install_pyenv(boxname)
  135. return <<-EOF
  136. echo 'export PYTHON_CONFIGURE_OPTS="--enable-shared"' >> ~/.bash_profile
  137. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
  138. echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
  139. . ~/.bash_profile
  140. curl -s -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
  141. echo 'eval "$(pyenv init --path)"' >> ~/.bash_profile
  142. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
  143. echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
  144. echo 'eval "$(pyenv init -)"' >> ~/.bashrc
  145. echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
  146. EOF
  147. end
  148. def install_pythons(boxname)
  149. return <<-EOF
  150. . ~/.bash_profile
  151. pyenv install 3.11.14 # tests, binary build
  152. pyenv rehash
  153. EOF
  154. end
  155. def build_sys_venv(boxname)
  156. return <<-EOF
  157. . ~/.bash_profile
  158. cd /vagrant/borg
  159. virtualenv --python=python3 borg-env
  160. EOF
  161. end
  162. def build_pyenv_venv(boxname)
  163. return <<-EOF
  164. . ~/.bash_profile
  165. cd /vagrant/borg
  166. # use the latest 3.11 release
  167. pyenv global 3.11.14
  168. pyenv virtualenv 3.11.14 borg-env
  169. ln -s ~/.pyenv/versions/borg-env .
  170. EOF
  171. end
  172. def install_borg(fuse)
  173. return <<-EOF
  174. . ~/.bash_profile
  175. cd /vagrant/borg
  176. . borg-env/bin/activate
  177. pip install -U wheel # upgrade wheel, might be too old
  178. cd borg
  179. pip install -r requirements.d/development.lock.txt
  180. python3 scripts/make.py clean
  181. pip install -e .[#{fuse}]
  182. EOF
  183. end
  184. def install_pyinstaller()
  185. return <<-EOF
  186. . ~/.bash_profile
  187. cd /vagrant/borg
  188. . borg-env/bin/activate
  189. pip install 'pyinstaller==6.7.0'
  190. EOF
  191. end
  192. def build_binary_with_pyinstaller(boxname)
  193. return <<-EOF
  194. . ~/.bash_profile
  195. cd /vagrant/borg
  196. . borg-env/bin/activate
  197. cd borg
  198. pyinstaller --clean --distpath=/vagrant/borg scripts/borg.exe.spec
  199. echo 'export PATH="/vagrant/borg:$PATH"' >> ~/.bash_profile
  200. cd .. && tar -czvf borg.tgz borg-dir
  201. EOF
  202. end
  203. def run_tests(boxname, skip_env)
  204. return <<-EOF
  205. . ~/.bash_profile
  206. cd /vagrant/borg/borg
  207. . ../borg-env/bin/activate
  208. if which pyenv 2> /dev/null; then
  209. # for testing, use the earliest point releases of the supported python versions:
  210. pyenv global 3.11.14
  211. pyenv local 3.11.14
  212. fi
  213. # otherwise: just use the system python
  214. # avoid that git complains about dubious ownership if we use fakeroot:
  215. git config --global --add safe.directory /vagrant/borg/borg
  216. # some OSes can only run specific test envs, e.g. because they miss FUSE support:
  217. export TOX_SKIP_ENV='#{skip_env}'
  218. if which fakeroot 2> /dev/null; then
  219. echo "Running tox WITH fakeroot -u"
  220. fakeroot -u tox --skip-missing-interpreters
  221. else
  222. echo "Running tox WITHOUT fakeroot -u"
  223. tox --skip-missing-interpreters
  224. fi
  225. EOF
  226. end
  227. def fs_init(user)
  228. return <<-EOF
  229. # clean up (wrong/outdated) stuff we likely got via rsync:
  230. rm -rf /vagrant/borg/borg/.tox 2> /dev/null
  231. rm -rf /vagrant/borg/borg/borgbackup.egg-info 2> /dev/null
  232. rm -rf /vagrant/borg/borg/__pycache__ 2> /dev/null
  233. find /vagrant/borg/borg/src -name '__pycache__' -exec rm -rf {} \\; 2> /dev/null
  234. chown -R #{user} /vagrant/borg
  235. touch ~#{user}/.bash_profile ; chown #{user} ~#{user}/.bash_profile
  236. echo 'export LANG=en_US.UTF-8' >> ~#{user}/.bash_profile
  237. echo 'export LC_CTYPE=en_US.UTF-8' >> ~#{user}/.bash_profile
  238. echo 'export XDISTN=#{$xdistn}' >> ~#{user}/.bash_profile
  239. EOF
  240. end
  241. Vagrant.configure(2) do |config|
  242. # use rsync to copy content to the folder
  243. config.vm.synced_folder ".", "/vagrant/borg/borg", :type => "rsync", :rsync__args => ["--verbose", "--archive", "--delete", "--exclude", ".python-version"], :rsync__chown => false
  244. # do not let the VM access . on the host machine via the default shared folder!
  245. config.vm.synced_folder ".", "/vagrant", disabled: true
  246. config.vm.provider :virtualbox do |v|
  247. #v.gui = true
  248. v.cpus = $cpus
  249. end
  250. config.vm.define "noble" do |b|
  251. b.vm.box = "bento/ubuntu-24.04"
  252. b.vm.provider :virtualbox do |v|
  253. v.memory = 1024 + $wmem
  254. end
  255. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  256. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  257. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("noble")
  258. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  259. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("noble", ".*none.*")
  260. end
  261. config.vm.define "jammy" do |b|
  262. b.vm.box = "ubuntu/jammy64"
  263. b.vm.provider :virtualbox do |v|
  264. v.memory = 1024 + $wmem
  265. end
  266. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  267. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  268. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("jammy")
  269. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  270. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("jammy", ".*none.*")
  271. end
  272. config.vm.define "trixie" do |b|
  273. b.vm.box = "debian/testing64"
  274. b.vm.provider :virtualbox do |v|
  275. v.memory = 1024 + $wmem
  276. end
  277. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  278. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  279. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("trixie")
  280. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("trixie")
  281. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("trixie")
  282. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  283. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  284. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("trixie")
  285. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("trixie", ".*none.*")
  286. end
  287. config.vm.define "bookworm" do |b|
  288. b.vm.box = "debian/bookworm64"
  289. b.vm.provider :virtualbox do |v|
  290. v.memory = 1024 + $wmem
  291. end
  292. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  293. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  294. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("bookworm")
  295. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("bookworm")
  296. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("bookworm")
  297. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  298. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  299. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("bookworm")
  300. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("bookworm", ".*none.*")
  301. end
  302. config.vm.define "bullseye" do |b|
  303. b.vm.box = "debian/bullseye64"
  304. b.vm.provider :virtualbox do |v|
  305. v.memory = 1024 + $wmem
  306. end
  307. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  308. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  309. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("bullseye")
  310. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("bullseye")
  311. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("bullseye")
  312. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  313. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  314. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("bullseye")
  315. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("bullseye", ".*none.*")
  316. end
  317. config.vm.define "freebsd13" do |b|
  318. b.vm.box = "generic/freebsd13"
  319. b.vm.provider :virtualbox do |v|
  320. v.memory = 1024 + $wmem
  321. end
  322. b.ssh.shell = "sh"
  323. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  324. b.vm.provision "packages freebsd", :type => :shell, :inline => packages_freebsd
  325. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("freebsd13")
  326. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("freebsd13")
  327. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("freebsd13")
  328. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  329. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  330. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("freebsd13")
  331. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("freebsd13", ".*(fuse3|none).*")
  332. end
  333. config.vm.define "freebsd14" do |b|
  334. b.vm.box = "generic/freebsd14"
  335. b.vm.provider :virtualbox do |v|
  336. v.memory = 1024 + $wmem
  337. end
  338. b.ssh.shell = "sh"
  339. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  340. b.vm.provision "packages freebsd", :type => :shell, :inline => packages_freebsd
  341. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("freebsd14")
  342. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("freebsd14")
  343. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("freebsd14")
  344. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  345. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  346. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("freebsd14")
  347. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("freebsd14", ".*(fuse3|none).*")
  348. end
  349. config.vm.define "openbsd7" do |b|
  350. b.vm.box = "l3system/openbsd77-amd64"
  351. b.vm.provider :virtualbox do |v|
  352. v.memory = 1024 + $wmem
  353. end
  354. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  355. b.vm.provision "packages openbsd", :type => :shell, :inline => packages_openbsd
  356. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openbsd7")
  357. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("nofuse")
  358. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openbsd7", ".*fuse.*")
  359. end
  360. config.vm.define "netbsd9" do |b|
  361. b.vm.box = "generic/netbsd9"
  362. b.vm.provider :virtualbox do |v|
  363. v.memory = 4096 + $wmem # need big /tmp tmpfs in RAM!
  364. end
  365. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  366. b.vm.provision "packages netbsd", :type => :shell, :inline => packages_netbsd
  367. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("netbsd9")
  368. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(false)
  369. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("netbsd9", ".*fuse.*")
  370. end
  371. # rsync on openindiana has troubles, does not set correct owner for /vagrant/borg and thus gives lots of
  372. # permission errors. can be manually fixed in the VM by: sudo chown -R vagrant /vagrant/borg ; then rsync again.
  373. config.vm.define "openindiana" do |b|
  374. b.vm.box = "openindiana/hipster"
  375. b.vm.provider :virtualbox do |v|
  376. v.memory = 2048 + $wmem
  377. end
  378. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  379. b.vm.provision "package update openindiana", :type => :shell, :inline => package_update_openindiana, :reboot => true
  380. b.vm.provision "packages openindiana", :type => :shell, :inline => packages_openindiana
  381. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openindiana")
  382. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("nofuse")
  383. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openindiana", ".*fuse.*")
  384. end
  385. end