Vagrantfile 17 KB

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