Vagrantfile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. apt update
  10. # install all the (security and other) updates
  11. apt dist-upgrade -y
  12. # for building borgbackup and dependencies:
  13. apt install -y libssl-dev libacl1-dev liblz4-dev libfuse-dev fuse pkg-config
  14. usermod -a -G fuse #{user}
  15. chgrp fuse /dev/fuse
  16. chmod 666 /dev/fuse
  17. apt install -y fakeroot build-essential git curl
  18. apt install -y python3-dev python3-setuptools python-virtualenv python3-virtualenv
  19. # for building python:
  20. apt install -y zlib1g-dev libbz2-dev libncurses5-dev libreadline-dev liblzma-dev libsqlite3-dev libffi-dev
  21. EOF
  22. end
  23. def packages_arch
  24. return <<-EOF
  25. echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
  26. locale-gen
  27. localectl set-locale LANG=en_US.UTF-8
  28. chown vagrant.vagrant /vagrant
  29. pacman --sync --noconfirm --refresh python-virtualenv python-pip
  30. EOF
  31. end
  32. def packages_freebsd
  33. return <<-EOF
  34. # in case the VM has no hostname set
  35. hostname freebsd
  36. # install all the (security and other) updates, base system
  37. freebsd-update --not-running-from-cron fetch install
  38. # for building borgbackup and dependencies:
  39. pkg install -y liblz4 zstd fusefs-libs pkgconf
  40. pkg install -y git bash # fakeroot causes lots of troubles on freebsd
  41. # for building python:
  42. pkg install -y sqlite3
  43. pkg install -y py27-virtualenv # provides "virtualenv" command
  44. pkg install -y python36 py36-virtualenv py36-pip
  45. # make sure there is a python3 command
  46. ln -s /usr/local/bin/python3.6 /usr/local/bin/python3
  47. # make bash default / work:
  48. chsh -s bash vagrant
  49. mount -t fdescfs fdesc /dev/fd
  50. echo 'fdesc /dev/fd fdescfs rw 0 0' >> /etc/fstab
  51. # make FUSE work
  52. echo 'fuse_load="YES"' >> /boot/loader.conf
  53. echo 'vfs.usermount=1' >> /etc/sysctl.conf
  54. kldload fuse
  55. sysctl vfs.usermount=1
  56. pw groupmod operator -M vagrant
  57. # /dev/fuse has group operator
  58. chmod 666 /dev/fuse
  59. # install all the (security and other) updates, packages
  60. pkg update
  61. yes | pkg upgrade
  62. EOF
  63. end
  64. def packages_darwin
  65. return <<-EOF
  66. # install all the (security and other) updates
  67. sudo softwareupdate --ignore iTunesX
  68. sudo softwareupdate --ignore iTunes
  69. sudo softwareupdate --ignore "Install macOS High Sierra"
  70. sudo softwareupdate --install --all
  71. # get osxfuse 3.x release code from github:
  72. curl -s -L https://github.com/osxfuse/osxfuse/releases/download/osxfuse-3.8.3/osxfuse-3.8.3.dmg >osxfuse.dmg
  73. MOUNTDIR=$(echo `hdiutil mount osxfuse.dmg | tail -1 | awk '{$1="" ; print $0}'` | xargs -0 echo) \
  74. && sudo installer -pkg "${MOUNTDIR}/Extras/FUSE for macOS 3.8.3.pkg" -target /
  75. sudo chown -R vagrant /usr/local # brew must be able to create stuff here
  76. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  77. brew update
  78. brew install openssl
  79. brew install zstd
  80. brew install lz4
  81. brew install xz # required for python lzma module
  82. brew install fakeroot
  83. brew install git
  84. brew install pkg-config
  85. EOF
  86. end
  87. def install_pyenv(boxname)
  88. return <<-EOF
  89. curl -s -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
  90. echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
  91. echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
  92. echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
  93. echo 'export PYTHON_CONFIGURE_OPTS="--enable-shared"' >> ~/.bash_profile
  94. EOF
  95. end
  96. def fix_pyenv_darwin(boxname)
  97. return <<-EOF
  98. echo 'export PYTHON_CONFIGURE_OPTS="--enable-framework"' >> ~/.bash_profile
  99. EOF
  100. end
  101. def install_pythons(boxname)
  102. return <<-EOF
  103. . ~/.bash_profile
  104. pyenv install 3.7.0 # tests
  105. pyenv install 3.6.0 # tests
  106. pyenv install 3.5.3 # tests, 3.5.3 is first to support openssl 1.1<k
  107. pyenv install 3.6.8 # binary build, use latest 3.6.x release
  108. pyenv rehash
  109. EOF
  110. end
  111. def build_sys_venv(boxname)
  112. return <<-EOF
  113. . ~/.bash_profile
  114. cd /vagrant/borg
  115. virtualenv --python=python3 borg-env
  116. EOF
  117. end
  118. def build_pyenv_venv(boxname)
  119. return <<-EOF
  120. . ~/.bash_profile
  121. cd /vagrant/borg
  122. # use the latest 3.6 release
  123. pyenv global 3.6.8
  124. pyenv virtualenv 3.6.8 borg-env
  125. ln -s ~/.pyenv/versions/borg-env .
  126. EOF
  127. end
  128. def install_borg(fuse)
  129. script = <<-EOF
  130. . ~/.bash_profile
  131. cd /vagrant/borg
  132. . borg-env/bin/activate
  133. pip install -U wheel # upgrade wheel, too old for 3.5
  134. cd borg
  135. pip install -r requirements.d/development.txt
  136. python setup.py clean
  137. EOF
  138. if fuse
  139. script += <<-EOF
  140. # by using [fuse], setup.py can handle different FUSE requirements:
  141. pip install -e .[fuse]
  142. EOF
  143. else
  144. script += <<-EOF
  145. pip install -e .
  146. # do not install llfuse into the virtualenvs built by tox:
  147. sed -i.bak '/fuse.txt/d' tox.ini
  148. EOF
  149. end
  150. return script
  151. end
  152. def install_pyinstaller()
  153. return <<-EOF
  154. . ~/.bash_profile
  155. cd /vagrant/borg
  156. . borg-env/bin/activate
  157. git clone https://github.com/thomaswaldmann/pyinstaller.git
  158. cd pyinstaller
  159. git checkout v3.3.1
  160. python setup.py install
  161. EOF
  162. end
  163. def build_binary_with_pyinstaller(boxname)
  164. return <<-EOF
  165. . ~/.bash_profile
  166. cd /vagrant/borg
  167. . borg-env/bin/activate
  168. cd borg
  169. pyinstaller --clean --distpath=/vagrant/borg scripts/borg.exe.spec
  170. echo 'export PATH="/vagrant/borg:$PATH"' >> ~/.bash_profile
  171. EOF
  172. end
  173. def run_tests(boxname)
  174. return <<-EOF
  175. . ~/.bash_profile
  176. cd /vagrant/borg/borg
  177. . ../borg-env/bin/activate
  178. if which pyenv 2> /dev/null; then
  179. # for testing, use the earliest point releases of the supported python versions:
  180. pyenv global 3.5.3 3.6.0 3.7.0
  181. pyenv local 3.5.3 3.6.0 3.7.0
  182. fi
  183. # otherwise: just use the system python
  184. if which fakeroot 2> /dev/null; then
  185. echo "Running tox WITH fakeroot -u"
  186. fakeroot -u tox --skip-missing-interpreters
  187. else
  188. echo "Running tox WITHOUT fakeroot -u"
  189. tox --skip-missing-interpreters
  190. fi
  191. EOF
  192. end
  193. def fs_init(user)
  194. return <<-EOF
  195. # clean up (wrong/outdated) stuff we likely got via rsync:
  196. rm -rf /vagrant/borg/borg/.tox 2> /dev/null
  197. rm -rf /vagrant/borg/borg/borgbackup.egg-info 2> /dev/null
  198. rm -rf /vagrant/borg/borg/__pycache__ 2> /dev/null
  199. find /vagrant/borg/borg/src -name '__pycache__' -exec rm -rf {} \\; 2> /dev/null
  200. chown -R #{user} /vagrant/borg
  201. touch ~#{user}/.bash_profile ; chown #{user} ~#{user}/.bash_profile
  202. echo 'export LANG=en_US.UTF-8' >> ~#{user}/.bash_profile
  203. echo 'export LC_CTYPE=en_US.UTF-8' >> ~#{user}/.bash_profile
  204. echo 'export XDISTN=#{$xdistn}' >> ~#{user}/.bash_profile
  205. EOF
  206. end
  207. Vagrant.configure(2) do |config|
  208. # use rsync to copy content to the folder
  209. config.vm.synced_folder ".", "/vagrant/borg/borg", :type => "rsync", :rsync__args => ["--verbose", "--archive", "--delete", "-z"], :rsync__chown => false
  210. # do not let the VM access . on the host machine via the default shared folder!
  211. config.vm.synced_folder ".", "/vagrant", disabled: true
  212. config.vm.provider :virtualbox do |v|
  213. #v.gui = true
  214. v.cpus = $cpus
  215. end
  216. config.vm.define "bionic64" do |b|
  217. b.vm.box = "ubuntu/bionic64"
  218. b.vm.provider :virtualbox do |v|
  219. v.memory = 1024 + $wmem
  220. end
  221. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  222. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  223. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("bionic64")
  224. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  225. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("bionic64")
  226. end
  227. config.vm.define "stretch64" do |b|
  228. b.vm.box = "debian/stretch64"
  229. b.vm.provider :virtualbox do |v|
  230. v.memory = 1024 + $wmem
  231. end
  232. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  233. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  234. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("stretch64")
  235. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("stretch64")
  236. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("stretch64")
  237. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  238. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  239. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("stretch64")
  240. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("stretch64")
  241. end
  242. config.vm.define "arch64" do |b|
  243. b.vm.box = "terrywang/archlinux"
  244. b.vm.provider :virtualbox do |v|
  245. v.memory = 1024 + $wmem
  246. end
  247. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  248. b.vm.provision "packages arch", :type => :shell, :privileged => true, :inline => packages_arch
  249. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("arch64")
  250. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  251. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("arch64")
  252. end
  253. config.vm.define "freebsd64" do |b|
  254. b.vm.box = "freebsd64-12"
  255. b.vm.provider :virtualbox do |v|
  256. v.memory = 1024 + $wmem
  257. end
  258. b.ssh.shell = "sh"
  259. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  260. b.vm.provision "packages freebsd", :type => :shell, :inline => packages_freebsd
  261. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("freebsd64")
  262. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  263. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  264. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("freebsd64")
  265. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("freebsd64")
  266. end
  267. config.vm.define "darwin64" do |b|
  268. b.vm.box = "jhcook/macos-sierra"
  269. b.vm.provider :virtualbox do |v|
  270. v.memory = 1536 + $wmem
  271. v.customize ['modifyvm', :id, '--ostype', 'MacOS1010_64']
  272. v.customize ['modifyvm', :id, '--paravirtprovider', 'default']
  273. # Adjust CPU settings according to
  274. # https://github.com/geerlingguy/macos-virtualbox-vm
  275. v.customize ['modifyvm', :id, '--cpuidset',
  276. '00000001', '000306a9', '00020800', '80000201', '178bfbff']
  277. # Disable USB variant requiring Virtualbox proprietary extension pack
  278. v.customize ["modifyvm", :id, '--usbehci', 'off', '--usbxhci', 'off']
  279. end
  280. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  281. b.vm.provision "packages darwin", :type => :shell, :privileged => false, :inline => packages_darwin
  282. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("darwin64")
  283. b.vm.provision "fix pyenv", :type => :shell, :privileged => false, :inline => fix_pyenv_darwin("darwin64")
  284. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("darwin64")
  285. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("darwin64")
  286. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  287. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  288. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("darwin64")
  289. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("darwin64")
  290. end
  291. # TODO: create more VMs with python 3.5+ and openssl 1.1.
  292. # See branch 1.1-maint for a better equipped Vagrantfile (but still on py34 and openssl 1.0).
  293. end