Vagrantfile 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 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 openssl-devel liblz4 fusefs-libs pkgconf
  40. pkg install -y fakeroot git bash
  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 install_pyenv(boxname)
  65. return <<-EOF
  66. curl -s -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
  67. echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
  68. echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
  69. echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
  70. echo 'export PYTHON_CONFIGURE_OPTS="--enable-shared"' >> ~/.bash_profile
  71. EOF
  72. end
  73. def fix_pyenv_darwin(boxname)
  74. return <<-EOF
  75. echo 'export PYTHON_CONFIGURE_OPTS="--enable-framework"' >> ~/.bash_profile
  76. EOF
  77. end
  78. def install_pythons(boxname)
  79. return <<-EOF
  80. . ~/.bash_profile
  81. pyenv install 3.6.0 # tests
  82. pyenv install 3.6.5 # binary build, use latest 3.6.x release
  83. pyenv rehash
  84. EOF
  85. end
  86. def build_sys_venv(boxname)
  87. return <<-EOF
  88. . ~/.bash_profile
  89. cd /vagrant/borg
  90. virtualenv --python=python3 borg-env
  91. EOF
  92. end
  93. def build_pyenv_venv(boxname)
  94. return <<-EOF
  95. . ~/.bash_profile
  96. cd /vagrant/borg
  97. # use the latest 3.6 release
  98. pyenv global 3.6.5
  99. pyenv virtualenv 3.6.5 borg-env
  100. ln -s ~/.pyenv/versions/borg-env .
  101. EOF
  102. end
  103. def install_borg(fuse)
  104. script = <<-EOF
  105. . ~/.bash_profile
  106. cd /vagrant/borg
  107. . borg-env/bin/activate
  108. pip install -U wheel # upgrade wheel, too old for 3.5
  109. cd borg
  110. pip install -r requirements.d/development.txt
  111. python setup.py clean
  112. EOF
  113. if fuse
  114. script += <<-EOF
  115. # by using [fuse], setup.py can handle different FUSE requirements:
  116. pip install -e .[fuse]
  117. EOF
  118. else
  119. script += <<-EOF
  120. pip install -e .
  121. # do not install llfuse into the virtualenvs built by tox:
  122. sed -i.bak '/fuse.txt/d' tox.ini
  123. EOF
  124. end
  125. return script
  126. end
  127. def install_pyinstaller()
  128. return <<-EOF
  129. . ~/.bash_profile
  130. cd /vagrant/borg
  131. . borg-env/bin/activate
  132. git clone https://github.com/thomaswaldmann/pyinstaller.git
  133. cd pyinstaller
  134. git checkout v3.3-fixed
  135. python setup.py install
  136. EOF
  137. end
  138. def build_binary_with_pyinstaller(boxname)
  139. return <<-EOF
  140. . ~/.bash_profile
  141. cd /vagrant/borg
  142. . borg-env/bin/activate
  143. cd borg
  144. pyinstaller --clean --distpath=/vagrant/borg scripts/borg.exe.spec
  145. echo 'export PATH="/vagrant/borg:$PATH"' >> ~/.bash_profile
  146. EOF
  147. end
  148. def run_tests(boxname)
  149. return <<-EOF
  150. . ~/.bash_profile
  151. cd /vagrant/borg/borg
  152. . ../borg-env/bin/activate
  153. if which pyenv 2> /dev/null; then
  154. # for testing, use the earliest point releases of the supported python versions:
  155. pyenv global 3.6.0
  156. pyenv local 3.6.0
  157. fi
  158. # otherwise: just use the system python
  159. if which fakeroot 2> /dev/null; then
  160. echo "Running tox WITH fakeroot -u"
  161. fakeroot -u tox --skip-missing-interpreters
  162. else
  163. echo "Running tox WITHOUT fakeroot -u"
  164. tox --skip-missing-interpreters
  165. fi
  166. EOF
  167. end
  168. def fs_init(user)
  169. return <<-EOF
  170. # clean up (wrong/outdated) stuff we likely got via rsync:
  171. rm -rf /vagrant/borg/borg/.tox 2> /dev/null
  172. rm -rf /vagrant/borg/borg/borgbackup.egg-info 2> /dev/null
  173. rm -rf /vagrant/borg/borg/__pycache__ 2> /dev/null
  174. find /vagrant/borg/borg/src -name '__pycache__' -exec rm -rf {} \\; 2> /dev/null
  175. chown -R #{user} /vagrant/borg
  176. touch ~#{user}/.bash_profile ; chown #{user} ~#{user}/.bash_profile
  177. echo 'export LANG=en_US.UTF-8' >> ~#{user}/.bash_profile
  178. echo 'export LC_CTYPE=en_US.UTF-8' >> ~#{user}/.bash_profile
  179. echo 'export XDISTN=#{$xdistn}' >> ~#{user}/.bash_profile
  180. EOF
  181. end
  182. Vagrant.configure(2) do |config|
  183. # use rsync to copy content to the folder
  184. config.vm.synced_folder ".", "/vagrant/borg/borg", :type => "rsync", :rsync__args => ["--verbose", "--archive", "--delete", "-z"], :rsync__chown => false
  185. # do not let the VM access . on the host machine via the default shared folder!
  186. config.vm.synced_folder ".", "/vagrant", disabled: true
  187. config.vm.provider :virtualbox do |v|
  188. #v.gui = true
  189. v.cpus = $cpus
  190. end
  191. config.vm.define "bionic64" do |b|
  192. b.vm.box = "ubuntu/bionic64"
  193. b.vm.provider :virtualbox do |v|
  194. v.memory = 1024 + $wmem
  195. end
  196. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  197. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  198. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("bionic64")
  199. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  200. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("bionic64")
  201. end
  202. config.vm.define "stretch64" do |b|
  203. b.vm.box = "debian/stretch64"
  204. b.vm.provider :virtualbox do |v|
  205. v.memory = 1024 + $wmem
  206. end
  207. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  208. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  209. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("stretch64")
  210. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("stretch64")
  211. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("stretch64")
  212. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  213. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  214. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("stretch64")
  215. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("stretch64")
  216. end
  217. config.vm.define "arch64" do |b|
  218. b.vm.box = "terrywang/archlinux"
  219. b.vm.provider :virtualbox do |v|
  220. v.memory = 1024 + $wmem
  221. end
  222. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  223. b.vm.provision "packages arch", :type => :shell, :privileged => true, :inline => packages_arch
  224. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("arch64")
  225. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  226. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("arch64")
  227. end
  228. config.vm.define "freebsd64" do |b|
  229. b.vm.box = "freebsd12-amd64"
  230. b.vm.provider :virtualbox do |v|
  231. v.memory = 1024 + $wmem
  232. end
  233. b.ssh.shell = "sh"
  234. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  235. b.vm.provision "packages freebsd", :type => :shell, :inline => packages_freebsd
  236. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("freebsd64")
  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("freebsd64")
  240. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("freebsd64")
  241. end
  242. # TODO: create more VMs with python 3.5+ and openssl 1.1.
  243. # See branch 1.1-maint for a better equipped Vagrantfile (but still on py34 and openssl 1.0).
  244. end