Vagrantfile 17 KB

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