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', '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 /usr/local/bin/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. ln -sf /usr/local/bin/virtualenv-3 /usr/local/bin/virtualenv
  82. EOF
  83. end
  84. def packages_darwin
  85. return <<-EOF
  86. # install all the (security and other) updates
  87. sudo softwareupdate --ignore iTunesX
  88. sudo softwareupdate --ignore iTunes
  89. sudo softwareupdate --ignore Safari
  90. sudo softwareupdate --ignore "Install macOS High Sierra"
  91. sudo softwareupdate --install --all
  92. which brew || CI=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  93. brew update > /dev/null
  94. brew install pkg-config readline openssl@1.1 zstd lz4 xz fakeroot git
  95. brew install --cask osxfuse
  96. brew upgrade # upgrade everything
  97. echo 'export PKG_CONFIG_PATH=/usr/local/opt/openssl@1.1/lib/pkgconfig' >> ~vagrant/.bash_profile
  98. EOF
  99. end
  100. def packages_openindiana
  101. return <<-EOF
  102. # needs separate provisioning step + reboot:
  103. #pkg update
  104. # already installed:
  105. #pkg install python-37 python-35 virtualenv-35 pip-35 clang-40 lz4 zstd git
  106. pkg install gcc-7
  107. ln -sf /usr/bin/python3.7 /usr/bin/python3
  108. python3 -m ensurepip
  109. ln -sf /usr/bin/pip3.7 /usr/bin/pip3
  110. pip3 install virtualenv
  111. EOF
  112. end
  113. def install_pyenv(boxname)
  114. return <<-EOF
  115. echo 'export PYTHON_CONFIGURE_OPTS="--enable-shared"' >> ~/.bash_profile
  116. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
  117. echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
  118. . ~/.bash_profile
  119. curl -s -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
  120. echo 'eval "$(pyenv init --path)"' >> ~/.bash_profile
  121. echo 'eval "$(pyenv init -)"' >> ~/.bashrc
  122. echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
  123. EOF
  124. end
  125. def fix_pyenv_darwin(boxname)
  126. return <<-EOF
  127. echo 'export PYTHON_CONFIGURE_OPTS="--enable-framework"' >> ~/.bash_profile
  128. EOF
  129. end
  130. def install_pythons(boxname)
  131. return <<-EOF
  132. . ~/.bash_profile
  133. pyenv install 3.10-dev # tests, version supporting openssl 1.1
  134. pyenv install 3.9.5 # tests, version supporting openssl 1.1, binary build
  135. pyenv install 3.8.0 # tests, version supporting openssl 1.1
  136. pyenv install 3.7.0 # tests, version supporting openssl 1.1
  137. pyenv install 3.6.2 # tests, version supporting openssl 1.1. broken for older 3.6.x.
  138. pyenv rehash
  139. EOF
  140. end
  141. def build_sys_venv(boxname)
  142. return <<-EOF
  143. . ~/.bash_profile
  144. cd /vagrant/borg
  145. virtualenv --python=python3 borg-env
  146. EOF
  147. end
  148. def build_pyenv_venv(boxname)
  149. return <<-EOF
  150. . ~/.bash_profile
  151. cd /vagrant/borg
  152. # use the latest 3.9 release
  153. pyenv global 3.9.5
  154. pyenv virtualenv 3.9.5 borg-env
  155. ln -s ~/.pyenv/versions/borg-env .
  156. EOF
  157. end
  158. def install_borg(fuse)
  159. return <<-EOF
  160. . ~/.bash_profile
  161. cd /vagrant/borg
  162. . borg-env/bin/activate
  163. pip install -U wheel # upgrade wheel, too old for 3.5
  164. cd borg
  165. pip install -r requirements.d/development.txt
  166. python setup.py clean
  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. git clone https://github.com/thomaswaldmann/pyinstaller.git
  176. cd pyinstaller
  177. git checkout v4.3-maint
  178. python setup.py install
  179. EOF
  180. end
  181. def build_binary_with_pyinstaller(boxname)
  182. return <<-EOF
  183. . ~/.bash_profile
  184. cd /vagrant/borg
  185. . borg-env/bin/activate
  186. cd borg
  187. pyinstaller --clean --distpath=/vagrant/borg scripts/borg.exe.spec
  188. echo 'export PATH="/vagrant/borg:$PATH"' >> ~/.bash_profile
  189. cd .. && tar -czvf borg.tgz borg-dir
  190. EOF
  191. end
  192. def run_tests(boxname, skip_env)
  193. return <<-EOF
  194. . ~/.bash_profile
  195. cd /vagrant/borg/borg
  196. . ../borg-env/bin/activate
  197. if which pyenv 2> /dev/null; then
  198. # for testing, use the earliest point releases of the supported python versions:
  199. pyenv global 3.6.2 3.7.0 3.8.0 3.9.5 3.10-dev
  200. pyenv local 3.6.2 3.7.0 3.8.0 3.9.5 3.10-dev
  201. fi
  202. # otherwise: just use the system python
  203. # some OSes can only run specific test envs, e.g. because they miss FUSE support:
  204. export TOX_SKIP_ENV='#{skip_env}'
  205. if which fakeroot 2> /dev/null; then
  206. echo "Running tox WITH fakeroot -u"
  207. fakeroot -u tox --skip-missing-interpreters
  208. else
  209. echo "Running tox WITHOUT fakeroot -u"
  210. tox --skip-missing-interpreters
  211. fi
  212. EOF
  213. end
  214. def fs_init(user)
  215. return <<-EOF
  216. # clean up (wrong/outdated) stuff we likely got via rsync:
  217. rm -rf /vagrant/borg/borg/.tox 2> /dev/null
  218. rm -rf /vagrant/borg/borg/borgbackup.egg-info 2> /dev/null
  219. rm -rf /vagrant/borg/borg/__pycache__ 2> /dev/null
  220. find /vagrant/borg/borg/src -name '__pycache__' -exec rm -rf {} \\; 2> /dev/null
  221. chown -R #{user} /vagrant/borg
  222. touch ~#{user}/.bash_profile ; chown #{user} ~#{user}/.bash_profile
  223. echo 'export LANG=en_US.UTF-8' >> ~#{user}/.bash_profile
  224. echo 'export LC_CTYPE=en_US.UTF-8' >> ~#{user}/.bash_profile
  225. echo 'export XDISTN=#{$xdistn}' >> ~#{user}/.bash_profile
  226. EOF
  227. end
  228. Vagrant.configure(2) do |config|
  229. # use rsync to copy content to the folder
  230. config.vm.synced_folder ".", "/vagrant/borg/borg", :type => "rsync", :rsync__args => ["--verbose", "--archive", "--delete", "--exclude", ".python-version"], :rsync__chown => false
  231. # do not let the VM access . on the host machine via the default shared folder!
  232. config.vm.synced_folder ".", "/vagrant", disabled: true
  233. config.vm.provider :virtualbox do |v|
  234. #v.gui = true
  235. v.cpus = $cpus
  236. end
  237. config.vm.define "focal64" do |b|
  238. b.vm.box = "ubuntu/focal64"
  239. b.vm.provider :virtualbox do |v|
  240. v.memory = 1024 + $wmem
  241. end
  242. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  243. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  244. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("focal64")
  245. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  246. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("focal64", ".*none.*")
  247. end
  248. config.vm.define "bionic64" do |b|
  249. b.vm.box = "ubuntu/bionic64"
  250. b.vm.provider :virtualbox do |v|
  251. v.memory = 1024 + $wmem
  252. end
  253. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  254. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  255. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("bionic64")
  256. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  257. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("bionic64", ".*(fuse3|none).*")
  258. end
  259. config.vm.define "bullseye64" do |b|
  260. b.vm.box = "debian/bullseye64"
  261. b.vm.provider :virtualbox do |v|
  262. v.memory = 1024 + $wmem
  263. end
  264. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  265. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  266. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("bullseye64")
  267. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("bullseye64")
  268. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("bullseye64")
  269. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  270. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  271. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("bullseye64")
  272. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("bullseye64", ".*none.*")
  273. end
  274. config.vm.define "buster64" do |b|
  275. b.vm.box = "debian/buster64"
  276. b.vm.provider :virtualbox do |v|
  277. v.memory = 1024 + $wmem
  278. end
  279. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  280. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  281. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("buster64")
  282. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("buster64")
  283. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("buster64")
  284. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  285. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  286. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("buster64")
  287. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("buster64", ".*none.*")
  288. end
  289. config.vm.define "stretch64" do |b|
  290. b.vm.box = "debian/stretch64"
  291. b.vm.provider :virtualbox do |v|
  292. v.memory = 1024 + $wmem
  293. end
  294. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  295. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  296. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("stretch64")
  297. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("stretch64")
  298. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("stretch64")
  299. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  300. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  301. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("stretch64")
  302. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("stretch64", ".*(fuse3|none).*")
  303. end
  304. config.vm.define "arch64" do |b|
  305. b.vm.box = "terrywang/archlinux"
  306. b.vm.provider :virtualbox do |v|
  307. v.memory = 1024 + $wmem
  308. end
  309. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  310. b.vm.provision "packages arch", :type => :shell, :privileged => true, :inline => packages_arch
  311. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("arch64")
  312. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  313. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("arch64", ".*none.*")
  314. end
  315. config.vm.define "freebsd64" do |b|
  316. b.vm.box = "freebsd121-64"
  317. b.vm.provider :virtualbox do |v|
  318. v.memory = 1024 + $wmem
  319. end
  320. b.ssh.shell = "sh"
  321. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  322. b.vm.provision "packages freebsd", :type => :shell, :inline => packages_freebsd
  323. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("freebsd64")
  324. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("freebsd64")
  325. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("freebsd64")
  326. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  327. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  328. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("freebsd64")
  329. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("freebsd64", ".*(fuse3|none).*")
  330. end
  331. config.vm.define "openbsd64" do |b|
  332. b.vm.box = "openbsd64-64"
  333. b.vm.provider :virtualbox do |v|
  334. v.memory = 1024 + $wmem
  335. end
  336. b.ssh.shell = "sh"
  337. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  338. b.vm.provision "packages openbsd", :type => :shell, :inline => packages_openbsd
  339. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openbsd64")
  340. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("nofuse")
  341. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openbsd64", ".*fuse.*")
  342. end
  343. config.vm.define "darwin64" do |b|
  344. b.vm.box = "macos-sierra"
  345. b.vm.provider :virtualbox do |v|
  346. v.memory = 2048 + $wmem
  347. v.customize ['modifyvm', :id, '--ostype', 'MacOS_64']
  348. v.customize ['modifyvm', :id, '--paravirtprovider', 'default']
  349. v.customize ['modifyvm', :id, '--nested-hw-virt', 'on']
  350. # Adjust CPU settings according to
  351. # https://github.com/geerlingguy/macos-virtualbox-vm
  352. v.customize ['modifyvm', :id, '--cpuidset',
  353. '00000001', '000306a9', '00020800', '80000201', '178bfbff']
  354. # Disable USB variant requiring Virtualbox proprietary extension pack
  355. v.customize ["modifyvm", :id, '--usbehci', 'off', '--usbxhci', 'off']
  356. end
  357. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  358. b.vm.provision "packages darwin", :type => :shell, :privileged => false, :inline => packages_darwin
  359. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("darwin64")
  360. b.vm.provision "fix pyenv", :type => :shell, :privileged => false, :inline => fix_pyenv_darwin("darwin64")
  361. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("darwin64")
  362. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("darwin64")
  363. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("llfuse")
  364. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  365. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("darwin64")
  366. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("darwin64", ".*(fuse3|none).*")
  367. end
  368. # rsync on openindiana has troubles, does not set correct owner for /vagrant/borg and thus gives lots of
  369. # permission errors. can be manually fixed in the VM by: sudo chown -R vagrant /vagrant/borg ; then rsync again.
  370. config.vm.define "openindiana64" do |b|
  371. b.vm.box = "openindiana"
  372. b.vm.provider :virtualbox do |v|
  373. v.memory = 1536 + $wmem
  374. end
  375. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  376. b.vm.provision "packages openindiana", :type => :shell, :inline => packages_openindiana
  377. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openindiana64")
  378. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("nofuse")
  379. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openindiana64", ".*fuse.*")
  380. end
  381. # TODO: create more VMs with python 3.6+ and openssl 1.1.
  382. # See branch 1.1-maint for a better equipped Vagrantfile (but still on py34 and openssl 1.0).
  383. end