Vagrantfile 7.2 KB

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