Vagrantfile 9.5 KB

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