Vagrantfile 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # Automated creation of testing environments / binaries on misc. platforms
  4. $cpus = Integer(ENV.fetch('VMCPUS', '4')) # create VMs with that many cpus
  5. $xdistn = Integer(ENV.fetch('XDISTN', '4')) # 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 libssl-dev libacl1-dev liblz4-dev libzstd-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. sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
  20. usermod -a -G fuse #{user}
  21. chgrp fuse /dev/fuse
  22. chmod 666 /dev/fuse
  23. apt install -y fakeroot build-essential git curl
  24. apt install -y python3-dev python3-setuptools virtualenv
  25. # for building python:
  26. apt install -y zlib1g-dev libbz2-dev libncurses5-dev libreadline-dev liblzma-dev libsqlite3-dev libffi-dev
  27. EOF
  28. end
  29. def packages_arch
  30. return <<-EOF
  31. echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
  32. locale-gen
  33. localectl set-locale LANG=en_US.UTF-8
  34. chown vagrant.vagrant /vagrant
  35. pacman -Syu --noconfirm python-virtualenv python-pip fuse2 fuse3
  36. modprobe fuse
  37. EOF
  38. end
  39. def packages_freebsd
  40. return <<-EOF
  41. # in case the VM has no hostname set
  42. hostname freebsd
  43. # install all the (security and other) updates, base system
  44. freebsd-update --not-running-from-cron fetch install
  45. # for building borgbackup and dependencies:
  46. pkg install -y liblz4 zstd pkgconf
  47. pkg install -y fusefs-libs || true
  48. pkg install -y fusefs-libs3 || true
  49. pkg install -y git bash # fakeroot causes lots of troubles on freebsd
  50. # for building python:
  51. pkg install -y python37 py37-sqlite3 py37-virtualenv py37-pip
  52. # make sure there is a python3 command
  53. ln -sf /usr/local/bin/python3.7 /usr/local/bin/python3
  54. # make bash default / work:
  55. chsh -s bash vagrant
  56. mount -t fdescfs fdesc /dev/fd
  57. echo 'fdesc /dev/fd fdescfs rw 0 0' >> /etc/fstab
  58. # make FUSE work
  59. echo 'fuse_load="YES"' >> /boot/loader.conf
  60. echo 'vfs.usermount=1' >> /etc/sysctl.conf
  61. kldload fuse
  62. sysctl vfs.usermount=1
  63. pw groupmod operator -M vagrant
  64. # /dev/fuse has group operator
  65. chmod 666 /dev/fuse
  66. # install all the (security and other) updates, packages
  67. pkg update
  68. yes | pkg upgrade
  69. echo 'export BORG_OPENSSL_PREFIX=/usr' >> ~vagrant/.bash_profile
  70. EOF
  71. end
  72. def packages_openbsd
  73. return <<-EOF
  74. pkg_add bash
  75. chsh -s bash vagrant
  76. pkg_add lz4
  77. pkg_add zstd
  78. pkg_add git # no fakeroot
  79. pkg_add py3-pip
  80. pkg_add py3-virtualenv
  81. EOF
  82. end
  83. def packages_netbsd
  84. return <<-EOF
  85. pkg_add zstd lz4 xxhash git
  86. sed -i 's/Version: /Version: 0.8.0/g' /usr/pkg/lib/pkgconfig/libxxhash.pc # bug in netbsd 9.2, version missing
  87. pkg_add bash
  88. chsh -s bash vagrant
  89. echo "export PROMPT_COMMAND=" >> ~vagrant/.bash_profile # bug in netbsd 9.2, .bash_profile broken for screen
  90. echo "export PROMPT_COMMAND=" >> ~root/.bash_profile # bug in netbsd 9.2, .bash_profile broken for screen
  91. pkg_add pkg-config
  92. # pkg_add fuse # llfuse supports netbsd, but is still buggy.
  93. # https://bitbucket.org/nikratio/python-llfuse/issues/70/perfuse_open-setsockopt-no-buffer-space
  94. pkg_add python38 py38-sqlite3 py38-pip py38-virtualenv
  95. ln -s /usr/pkg/bin/python3.8 /usr/pkg/bin/python
  96. ln -s /usr/pkg/bin/python3.8 /usr/pkg/bin/python3
  97. ln -s /usr/pkg/bin/pip3.8 /usr/pkg/bin/pip
  98. ln -s /usr/pkg/bin/pip3.8 /usr/pkg/bin/pip3
  99. ln -s /usr/pkg/bin/virtualenv-3.8 /usr/pkg/bin/virtualenv
  100. ln -s /usr/pkg/bin/virtualenv-3.8 /usr/pkg/bin/virtualenv3
  101. EOF
  102. end
  103. def packages_darwin
  104. return <<-EOF
  105. # install all the (security and other) updates
  106. sudo softwareupdate --ignore iTunesX
  107. sudo softwareupdate --ignore iTunes
  108. sudo softwareupdate --ignore Safari
  109. sudo softwareupdate --ignore "Install macOS High Sierra"
  110. sudo softwareupdate --install --all
  111. which brew || CI=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  112. brew update > /dev/null
  113. brew install pkg-config readline openssl@1.1 zstd lz4 xz fakeroot git
  114. brew install --cask osxfuse
  115. brew upgrade # upgrade everything
  116. echo 'export PKG_CONFIG_PATH=/usr/local/opt/openssl@1.1/lib/pkgconfig' >> ~vagrant/.bash_profile
  117. EOF
  118. end
  119. def packages_openindiana
  120. return <<-EOF
  121. # needs separate provisioning step + reboot:
  122. #pkg update
  123. # already installed:
  124. #pkg install python-37 python-35 virtualenv-35 pip-35 clang-40 lz4 zstd git
  125. pkg install gcc-7
  126. ln -sf /usr/bin/python3.7 /usr/bin/python3
  127. python3 -m ensurepip
  128. ln -sf /usr/bin/pip3.7 /usr/bin/pip3
  129. pip3 install virtualenv
  130. EOF
  131. end
  132. def install_pyenv(boxname)
  133. return <<-EOF
  134. echo 'export PYTHON_CONFIGURE_OPTS="--enable-shared"' >> ~/.bash_profile
  135. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
  136. echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
  137. . ~/.bash_profile
  138. curl -s -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
  139. echo 'eval "$(pyenv init --path)"' >> ~/.bash_profile
  140. echo 'eval "$(pyenv init -)"' >> ~/.bashrc
  141. echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
  142. EOF
  143. end
  144. def fix_pyenv_darwin(boxname)
  145. return <<-EOF
  146. echo 'export PYTHON_CONFIGURE_OPTS="--enable-framework"' >> ~/.bash_profile
  147. EOF
  148. end
  149. def install_pythons(boxname)
  150. return <<-EOF
  151. . ~/.bash_profile
  152. pyenv install 3.10-dev # tests, version supporting openssl 1.1
  153. pyenv install 3.9.5 # tests, version supporting openssl 1.1, binary build
  154. pyenv install 3.8.0 # tests, version supporting openssl 1.1
  155. pyenv install 3.7.0 # tests, version supporting openssl 1.1
  156. pyenv rehash
  157. EOF
  158. end
  159. def build_sys_venv(boxname)
  160. return <<-EOF
  161. . ~/.bash_profile
  162. cd /vagrant/borg
  163. virtualenv --python=python3 borg-env
  164. EOF
  165. end
  166. def build_pyenv_venv(boxname)
  167. return <<-EOF
  168. . ~/.bash_profile
  169. cd /vagrant/borg
  170. # use the latest 3.9 release
  171. pyenv global 3.9.5
  172. pyenv virtualenv 3.9.5 borg-env
  173. ln -s ~/.pyenv/versions/borg-env .
  174. EOF
  175. end
  176. def install_borg(fuse)
  177. return <<-EOF
  178. . ~/.bash_profile
  179. cd /vagrant/borg
  180. . borg-env/bin/activate
  181. pip install -U wheel # upgrade wheel, might be too old
  182. cd borg
  183. pip install -r requirements.d/development.txt
  184. python setup.py clean
  185. pip install -e .[#{fuse}]
  186. EOF
  187. end
  188. def install_pyinstaller()
  189. return <<-EOF
  190. . ~/.bash_profile
  191. cd /vagrant/borg
  192. . borg-env/bin/activate
  193. git clone https://github.com/thomaswaldmann/pyinstaller.git
  194. cd pyinstaller
  195. git checkout v4.3-maint
  196. python setup.py install
  197. EOF
  198. end
  199. def build_binary_with_pyinstaller(boxname)
  200. return <<-EOF
  201. . ~/.bash_profile
  202. cd /vagrant/borg
  203. . borg-env/bin/activate
  204. cd borg
  205. pyinstaller --clean --distpath=/vagrant/borg scripts/borg.exe.spec
  206. echo 'export PATH="/vagrant/borg:$PATH"' >> ~/.bash_profile
  207. cd .. && tar -czvf borg.tgz borg-dir
  208. EOF
  209. end
  210. def run_tests(boxname, skip_env)
  211. return <<-EOF
  212. . ~/.bash_profile
  213. cd /vagrant/borg/borg
  214. . ../borg-env/bin/activate
  215. if which pyenv 2> /dev/null; then
  216. # for testing, use the earliest point releases of the supported python versions:
  217. pyenv global 3.7.0 3.8.0 3.9.5 3.10-dev
  218. pyenv local 3.7.0 3.8.0 3.9.5 3.10-dev
  219. fi
  220. # otherwise: just use the system python
  221. # some OSes can only run specific test envs, e.g. because they miss FUSE support:
  222. export TOX_SKIP_ENV='#{skip_env}'
  223. if which fakeroot 2> /dev/null; then
  224. echo "Running tox WITH fakeroot -u"
  225. fakeroot -u tox --skip-missing-interpreters
  226. else
  227. echo "Running tox WITHOUT fakeroot -u"
  228. tox --skip-missing-interpreters
  229. fi
  230. EOF
  231. end
  232. def fs_init(user)
  233. return <<-EOF
  234. # clean up (wrong/outdated) stuff we likely got via rsync:
  235. rm -rf /vagrant/borg/borg/.tox 2> /dev/null
  236. rm -rf /vagrant/borg/borg/borgbackup.egg-info 2> /dev/null
  237. rm -rf /vagrant/borg/borg/__pycache__ 2> /dev/null
  238. find /vagrant/borg/borg/src -name '__pycache__' -exec rm -rf {} \\; 2> /dev/null
  239. chown -R #{user} /vagrant/borg
  240. touch ~#{user}/.bash_profile ; chown #{user} ~#{user}/.bash_profile
  241. echo 'export LANG=en_US.UTF-8' >> ~#{user}/.bash_profile
  242. echo 'export LC_CTYPE=en_US.UTF-8' >> ~#{user}/.bash_profile
  243. echo 'export XDISTN=#{$xdistn}' >> ~#{user}/.bash_profile
  244. EOF
  245. end
  246. Vagrant.configure(2) do |config|
  247. # use rsync to copy content to the folder
  248. config.vm.synced_folder ".", "/vagrant/borg/borg", :type => "rsync", :rsync__args => ["--verbose", "--archive", "--delete", "--exclude", ".python-version"], :rsync__chown => false
  249. # do not let the VM access . on the host machine via the default shared folder!
  250. config.vm.synced_folder ".", "/vagrant", disabled: true
  251. config.vm.provider :virtualbox do |v|
  252. #v.gui = true
  253. v.cpus = $cpus
  254. end
  255. config.vm.define "focal64" do |b|
  256. b.vm.box = "ubuntu/focal64"
  257. b.vm.provider :virtualbox do |v|
  258. v.memory = 1024 + $wmem
  259. end
  260. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  261. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  262. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("focal64")
  263. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  264. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("focal64", ".*none.*")
  265. end
  266. config.vm.define "bullseye64" do |b|
  267. b.vm.box = "debian/bullseye64"
  268. b.vm.provider :virtualbox do |v|
  269. v.memory = 1024 + $wmem
  270. end
  271. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  272. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  273. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("bullseye64")
  274. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("bullseye64")
  275. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("bullseye64")
  276. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  277. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  278. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("bullseye64")
  279. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("bullseye64", ".*none.*")
  280. end
  281. config.vm.define "buster64" do |b|
  282. b.vm.box = "debian/buster64"
  283. b.vm.provider :virtualbox do |v|
  284. v.memory = 1024 + $wmem
  285. end
  286. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  287. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  288. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("buster64")
  289. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("buster64")
  290. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("buster64")
  291. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  292. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  293. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("buster64")
  294. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("buster64", ".*none.*")
  295. end
  296. config.vm.define "stretch64" do |b|
  297. b.vm.box = "debian/stretch64"
  298. b.vm.provider :virtualbox do |v|
  299. v.memory = 1024 + $wmem
  300. end
  301. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  302. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  303. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("stretch64")
  304. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("stretch64")
  305. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("stretch64")
  306. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  307. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  308. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("stretch64")
  309. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("stretch64", ".*(fuse3|none).*")
  310. end
  311. config.vm.define "freebsd64" do |b|
  312. b.vm.box = "freebsd121-64"
  313. b.vm.provider :virtualbox do |v|
  314. v.memory = 1024 + $wmem
  315. end
  316. b.ssh.shell = "sh"
  317. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  318. b.vm.provision "packages freebsd", :type => :shell, :inline => packages_freebsd
  319. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("freebsd64")
  320. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("freebsd64")
  321. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("freebsd64")
  322. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  323. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  324. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("freebsd64")
  325. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("freebsd64", ".*(fuse3|none).*")
  326. end
  327. config.vm.define "openbsd64" do |b|
  328. b.vm.box = "generic/openbsd6"
  329. b.vm.provider :virtualbox do |v|
  330. v.memory = 1024 + $wmem
  331. end
  332. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  333. b.vm.provision "packages openbsd", :type => :shell, :inline => packages_openbsd
  334. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openbsd64")
  335. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("nofuse")
  336. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openbsd64", ".*fuse.*")
  337. end
  338. config.vm.define "netbsd64" do |b|
  339. b.vm.box = "generic/netbsd9"
  340. b.vm.provider :virtualbox do |v|
  341. v.memory = 2048 + $wmem
  342. end
  343. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  344. b.vm.provision "packages netbsd", :type => :shell, :inline => packages_netbsd
  345. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("netbsd64")
  346. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(false)
  347. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("netbsd64", ".*fuse.*")
  348. end
  349. config.vm.define "darwin64" do |b|
  350. b.vm.box = "macos-sierra"
  351. b.vm.provider :virtualbox do |v|
  352. v.memory = 2048 + $wmem
  353. v.customize ['modifyvm', :id, '--ostype', 'MacOS_64']
  354. v.customize ['modifyvm', :id, '--paravirtprovider', 'default']
  355. v.customize ['modifyvm', :id, '--nested-hw-virt', 'on']
  356. # Adjust CPU settings according to
  357. # https://github.com/geerlingguy/macos-virtualbox-vm
  358. v.customize ['modifyvm', :id, '--cpuidset',
  359. '00000001', '000306a9', '00020800', '80000201', '178bfbff']
  360. # Disable USB variant requiring Virtualbox proprietary extension pack
  361. v.customize ["modifyvm", :id, '--usbehci', 'off', '--usbxhci', 'off']
  362. end
  363. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  364. b.vm.provision "packages darwin", :type => :shell, :privileged => false, :inline => packages_darwin
  365. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("darwin64")
  366. b.vm.provision "fix pyenv", :type => :shell, :privileged => false, :inline => fix_pyenv_darwin("darwin64")
  367. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("darwin64")
  368. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("darwin64")
  369. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  370. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  371. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("darwin64")
  372. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("darwin64", ".*(fuse3|none).*")
  373. end
  374. # rsync on openindiana has troubles, does not set correct owner for /vagrant/borg and thus gives lots of
  375. # permission errors. can be manually fixed in the VM by: sudo chown -R vagrant /vagrant/borg ; then rsync again.
  376. config.vm.define "openindiana64" do |b|
  377. b.vm.box = "openindiana"
  378. b.vm.provider :virtualbox do |v|
  379. v.memory = 1536 + $wmem
  380. end
  381. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  382. b.vm.provision "packages openindiana", :type => :shell, :inline => packages_openindiana
  383. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openindiana64")
  384. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("nofuse")
  385. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openindiana64", ".*fuse.*")
  386. end
  387. # TODO: create more VMs with python 3.7+ and openssl 1.1.
  388. # See branch 1.1-maint for a better equipped Vagrantfile (but still on py34 and openssl 1.0).
  389. end