Vagrantfile 17 KB

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