Vagrantfile 7.3 KB

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