Vagrantfile 6.6 KB

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