Vagrantfile 17 KB

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