Vagrantfile 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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 libfuse-dev fuse pkg-config
  16. usermod -a -G fuse #{user}
  17. chgrp fuse /dev/fuse
  18. chmod 666 /dev/fuse
  19. apt install -y fakeroot build-essential git curl
  20. apt install -y python3-dev python3-setuptools python-virtualenv python3-virtualenv
  21. # for building python:
  22. apt install -y zlib1g-dev libbz2-dev libncurses5-dev libreadline-dev liblzma-dev libsqlite3-dev libffi-dev
  23. EOF
  24. end
  25. def packages_arch
  26. return <<-EOF
  27. echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
  28. locale-gen
  29. localectl set-locale LANG=en_US.UTF-8
  30. chown vagrant.vagrant /vagrant
  31. pacman --sync --noconfirm --refresh python-virtualenv python-pip
  32. EOF
  33. end
  34. def packages_freebsd
  35. return <<-EOF
  36. # in case the VM has no hostname set
  37. hostname freebsd
  38. # install all the (security and other) updates, base system
  39. freebsd-update --not-running-from-cron fetch install
  40. # for building borgbackup and dependencies:
  41. pkg install -y liblz4 zstd fusefs-libs pkgconf
  42. pkg install -y git bash # fakeroot causes lots of troubles on freebsd
  43. # for building python:
  44. pkg install -y sqlite3
  45. pkg install -y py27-virtualenv # provides "virtualenv" command
  46. pkg install -y python36 py36-virtualenv py36-pip
  47. # make sure there is a python3 command
  48. ln -s /usr/local/bin/python3.6 /usr/local/bin/python3
  49. # make bash default / work:
  50. chsh -s bash vagrant
  51. mount -t fdescfs fdesc /dev/fd
  52. echo 'fdesc /dev/fd fdescfs rw 0 0' >> /etc/fstab
  53. # make FUSE work
  54. echo 'fuse_load="YES"' >> /boot/loader.conf
  55. echo 'vfs.usermount=1' >> /etc/sysctl.conf
  56. kldload fuse
  57. sysctl vfs.usermount=1
  58. pw groupmod operator -M vagrant
  59. # /dev/fuse has group operator
  60. chmod 666 /dev/fuse
  61. # install all the (security and other) updates, packages
  62. pkg update
  63. yes | pkg upgrade
  64. echo 'export BORG_OPENSSL_PREFIX=/usr' >> ~vagrant/.bash_profile
  65. EOF
  66. end
  67. def packages_openbsd
  68. return <<-EOF
  69. pkg_add bash
  70. chsh -s /usr/local/bin/bash vagrant
  71. pkg_add lz4
  72. pkg_add zstd
  73. pkg_add git # no fakeroot
  74. pkg_add py3-pip
  75. pkg_add py3-virtualenv
  76. ln -sf /usr/local/bin/virtualenv-3 /usr/local/bin/virtualenv
  77. EOF
  78. end
  79. def packages_darwin
  80. return <<-EOF
  81. # install all the (security and other) updates
  82. sudo softwareupdate --ignore iTunesX
  83. sudo softwareupdate --ignore iTunes
  84. sudo softwareupdate --ignore "Install macOS High Sierra"
  85. sudo softwareupdate --install --all
  86. # get osxfuse 3.x release code from github:
  87. curl -s -L https://github.com/osxfuse/osxfuse/releases/download/osxfuse-3.8.3/osxfuse-3.8.3.dmg >osxfuse.dmg
  88. MOUNTDIR=$(echo `hdiutil mount osxfuse.dmg | tail -1 | awk '{$1="" ; print $0}'` | xargs -0 echo) \
  89. && sudo installer -pkg "${MOUNTDIR}/Extras/FUSE for macOS 3.8.3.pkg" -target /
  90. sudo chown -R vagrant /usr/local # brew must be able to create stuff here
  91. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  92. brew update > /dev/null
  93. brew install pkg-config || brew upgrade pkg-config
  94. brew install readline || brew upgrade readline
  95. brew install openssl@1.1 || brew upgrade openssl@1.1
  96. brew install zstd || brew upgrade zstd
  97. brew install lz4 || brew upgrade lz4
  98. brew install xz || brew upgrade xz # required for python lzma module
  99. brew install fakeroot || brew upgrade fakeroot
  100. brew install git || brew upgrade git
  101. echo 'export PKG_CONFIG_PATH=/usr/local/opt/openssl@1.1/lib/pkgconfig' >> ~vagrant/.bash_profile
  102. EOF
  103. end
  104. def packages_openindiana
  105. return <<-EOF
  106. # needs separate provisioning step + reboot:
  107. #pkg update
  108. # already installed:
  109. #pkg install python-35 virtualenv-35 pip-35 clang-40 lz4 zstd git
  110. ln -sf /usr/bin/python3.5 /usr/bin/pyton3
  111. ln -sf /usr/bin/virtualenv-3.5 /usr/bin/virtualenv
  112. ln -sf /usr/bin/pip-3.5 /usr/bin/pip
  113. EOF
  114. end
  115. def install_pyenv(boxname)
  116. return <<-EOF
  117. curl -s -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
  118. echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
  119. echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
  120. echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
  121. echo 'export PYTHON_CONFIGURE_OPTS="--enable-shared"' >> ~/.bash_profile
  122. EOF
  123. end
  124. def fix_pyenv_darwin(boxname)
  125. return <<-EOF
  126. echo 'export PYTHON_CONFIGURE_OPTS="--enable-framework"' >> ~/.bash_profile
  127. EOF
  128. end
  129. def install_pythons(boxname)
  130. return <<-EOF
  131. . ~/.bash_profile
  132. pyenv install 3.8.0 # tests, version supporting openssl 1.1
  133. pyenv install 3.7.0 # tests, version supporting openssl 1.1
  134. pyenv install 3.6.9 # binary build, tests, version supporting openssl 1.1
  135. pyenv install 3.5.3 # tests, 3.5.3 is first to support openssl 1.1
  136. pyenv rehash
  137. EOF
  138. end
  139. def build_sys_venv(boxname)
  140. return <<-EOF
  141. . ~/.bash_profile
  142. cd /vagrant/borg
  143. virtualenv --python=python3 borg-env
  144. EOF
  145. end
  146. def build_pyenv_venv(boxname)
  147. return <<-EOF
  148. . ~/.bash_profile
  149. cd /vagrant/borg
  150. # use the latest 3.6 release
  151. pyenv global 3.6.9
  152. pyenv virtualenv 3.6.9 borg-env
  153. ln -s ~/.pyenv/versions/borg-env .
  154. EOF
  155. end
  156. def install_borg(fuse)
  157. script = <<-EOF
  158. . ~/.bash_profile
  159. cd /vagrant/borg
  160. . borg-env/bin/activate
  161. pip install -U wheel # upgrade wheel, too old for 3.5
  162. cd borg
  163. pip install -r requirements.d/development.txt
  164. python setup.py clean
  165. EOF
  166. if fuse
  167. script += <<-EOF
  168. # by using [fuse], setup.py can handle different FUSE requirements:
  169. pip install -e .[fuse]
  170. EOF
  171. else
  172. script += <<-EOF
  173. pip install -e .
  174. # do not install llfuse into the virtualenvs built by tox:
  175. sed -i.bak '/fuse.txt/d' tox.ini
  176. EOF
  177. end
  178. return script
  179. end
  180. def install_pyinstaller()
  181. return <<-EOF
  182. . ~/.bash_profile
  183. cd /vagrant/borg
  184. . borg-env/bin/activate
  185. git clone https://github.com/thomaswaldmann/pyinstaller.git
  186. cd pyinstaller
  187. git checkout v3.5-maint
  188. python setup.py install
  189. EOF
  190. end
  191. def build_binary_with_pyinstaller(boxname)
  192. return <<-EOF
  193. . ~/.bash_profile
  194. cd /vagrant/borg
  195. . borg-env/bin/activate
  196. cd borg
  197. pyinstaller --clean --distpath=/vagrant/borg scripts/borg.exe.spec
  198. echo 'export PATH="/vagrant/borg:$PATH"' >> ~/.bash_profile
  199. EOF
  200. end
  201. def run_tests(boxname)
  202. return <<-EOF
  203. . ~/.bash_profile
  204. cd /vagrant/borg/borg
  205. . ../borg-env/bin/activate
  206. if which pyenv 2> /dev/null; then
  207. # for testing, use the earliest point releases of the supported python versions:
  208. pyenv global 3.5.3 3.6.9 3.7.0 3.8.0
  209. pyenv local 3.5.3 3.6.9 3.7.0 3.8.0
  210. fi
  211. # otherwise: just use the system python
  212. if which fakeroot 2> /dev/null; then
  213. echo "Running tox WITH fakeroot -u"
  214. fakeroot -u tox --skip-missing-interpreters -e py35,py36,py37,py38
  215. else
  216. echo "Running tox WITHOUT fakeroot -u"
  217. tox --skip-missing-interpreters -e py35,py36,py37,py38
  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", "-z"], :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(true)
  253. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("focal64")
  254. end
  255. config.vm.define "bionic64" do |b|
  256. b.vm.box = "ubuntu/bionic64"
  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 "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("bionic64")
  263. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  264. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("bionic64")
  265. end
  266. config.vm.define "buster64" do |b|
  267. b.vm.box = "debian/buster64"
  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("buster64")
  274. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("buster64")
  275. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("buster64")
  276. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  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("buster64")
  279. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("buster64")
  280. end
  281. config.vm.define "stretch64" do |b|
  282. b.vm.box = "debian/stretch64"
  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 debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  288. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("stretch64")
  289. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("stretch64")
  290. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("stretch64")
  291. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  292. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  293. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("stretch64")
  294. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("stretch64")
  295. end
  296. config.vm.define "arch64" do |b|
  297. b.vm.box = "terrywang/archlinux"
  298. b.vm.provider :virtualbox do |v|
  299. v.memory = 1024 + $wmem
  300. end
  301. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  302. b.vm.provision "packages arch", :type => :shell, :privileged => true, :inline => packages_arch
  303. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("arch64")
  304. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  305. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("arch64")
  306. end
  307. config.vm.define "freebsd64" do |b|
  308. b.vm.box = "freebsd12-64"
  309. b.vm.provider :virtualbox do |v|
  310. v.memory = 1024 + $wmem
  311. end
  312. b.ssh.shell = "sh"
  313. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  314. b.vm.provision "packages freebsd", :type => :shell, :inline => packages_freebsd
  315. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("freebsd64")
  316. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  317. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  318. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("freebsd64")
  319. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("freebsd64")
  320. end
  321. config.vm.define "openbsd64" do |b|
  322. b.vm.box = "openbsd64-64"
  323. b.vm.provider :virtualbox do |v|
  324. v.memory = 1024 + $wmem
  325. end
  326. b.ssh.shell = "sh"
  327. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  328. b.vm.provision "packages openbsd", :type => :shell, :inline => packages_openbsd
  329. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openbsd64")
  330. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(false)
  331. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openbsd64")
  332. end
  333. config.vm.define "darwin64" do |b|
  334. b.vm.box = "jhcook/macos-sierra"
  335. b.vm.provider :virtualbox do |v|
  336. v.memory = 1536 + $wmem
  337. v.customize ['modifyvm', :id, '--ostype', 'MacOS1010_64']
  338. v.customize ['modifyvm', :id, '--paravirtprovider', 'default']
  339. # Adjust CPU settings according to
  340. # https://github.com/geerlingguy/macos-virtualbox-vm
  341. v.customize ['modifyvm', :id, '--cpuidset',
  342. '00000001', '000306a9', '00020800', '80000201', '178bfbff']
  343. # Disable USB variant requiring Virtualbox proprietary extension pack
  344. v.customize ["modifyvm", :id, '--usbehci', 'off', '--usbxhci', 'off']
  345. end
  346. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  347. b.vm.provision "packages darwin", :type => :shell, :privileged => false, :inline => packages_darwin
  348. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("darwin64")
  349. b.vm.provision "fix pyenv", :type => :shell, :privileged => false, :inline => fix_pyenv_darwin("darwin64")
  350. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("darwin64")
  351. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("darwin64")
  352. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  353. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  354. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("darwin64")
  355. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("darwin64")
  356. end
  357. # rsync on openindiana has troubles, does not set correct owner for /vagrant/borg and thus gives lots of
  358. # permission errors. can be manually fixed in the VM by: sudo chown -R vagrant /vagrant/borg ; then rsync again.
  359. config.vm.define "openindiana64" do |b|
  360. b.vm.box = "openindiana"
  361. b.vm.provider :virtualbox do |v|
  362. v.memory = 1536 + $wmem
  363. end
  364. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  365. b.vm.provision "packages openindiana", :type => :shell, :inline => packages_openindiana
  366. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openindiana64")
  367. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(false)
  368. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openindiana64")
  369. end
  370. # TODO: create more VMs with python 3.5+ and openssl 1.1.
  371. # See branch 1.1-maint for a better equipped Vagrantfile (but still on py34 and openssl 1.0).
  372. end