Vagrantfile 19 KB

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