Vagrantfile 7.4 KB

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