2
0

Vagrantfile 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. # clean up (wrong/outdated) stuff we likely got via rsync:
  79. rm -rf __pycache__
  80. find src -name '__pycache__' -exec rm -rf {} \\;
  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. chown -R #{user} /vagrant/borg
  142. touch ~#{user}/.bash_profile ; chown #{user} ~#{user}/.bash_profile
  143. echo 'export LANG=en_US.UTF-8' >> ~#{user}/.bash_profile
  144. echo 'export LC_CTYPE=en_US.UTF-8' >> ~#{user}/.bash_profile
  145. echo 'export XDISTN=#{$xdistn}' >> ~#{user}/.bash_profile
  146. EOF
  147. end
  148. Vagrant.configure(2) do |config|
  149. # use rsync to copy content to the folder
  150. config.vm.synced_folder ".", "/vagrant/borg/borg", :type => "rsync", :rsync__args => ["--verbose", "--archive", "--delete", "-z"], :rsync__chown => false
  151. # do not let the VM access . on the host machine via the default shared folder!
  152. config.vm.synced_folder ".", "/vagrant", disabled: true
  153. config.vm.provider :virtualbox do |v|
  154. #v.gui = true
  155. v.cpus = $cpus
  156. end
  157. config.vm.define "xenial64" do |b|
  158. b.vm.box = "ubuntu/xenial64"
  159. b.vm.provider :virtualbox do |v|
  160. v.memory = 1024 + $wmem
  161. end
  162. b.vm.provision "fs init", :type => :shell, :inline => fs_init("ubuntu")
  163. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("ubuntu")
  164. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("xenial64")
  165. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  166. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("xenial64")
  167. end
  168. config.vm.define "stretch64" do |b|
  169. b.vm.box = "debian/stretch64"
  170. b.vm.provider :virtualbox do |v|
  171. v.memory = 1024 + $wmem
  172. end
  173. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  174. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid("vagrant")
  175. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("stretch64")
  176. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  177. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller()
  178. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("stretch64")
  179. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("stretch64")
  180. end
  181. config.vm.define "arch64" do |b|
  182. b.vm.box = "terrywang/archlinux"
  183. b.vm.provider :virtualbox do |v|
  184. v.memory = 1024 + $wmem
  185. end
  186. b.vm.provision "fs init", :type => :shell, :inline => fs_init("vagrant")
  187. b.vm.provision "packages arch", :type => :shell, :privileged => true, :inline => packages_arch
  188. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("arch64")
  189. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg(true)
  190. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("arch64")
  191. end
  192. # TODO: create more VMs with python 3.5+ and openssl 1.1.
  193. # See branch 1.1-maint for a better equipped Vagrantfile (but still on py34 and openssl 1.0).
  194. end