Vagrantfile 9.5 KB

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