Vagrantfile 18 KB

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