Vagrantfile 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # Automated creation of testing environments on misc. platforms
  4. # Usage:
  5. # vagrant up OS
  6. # vagrant ssh OS -c command
  7. # vagrant halt OS
  8. def packages_prepare_wheezy
  9. return <<-EOF
  10. # debian 7 wheezy does not have lz4, but it is available from wheezy-backports:
  11. echo "deb http://http.debian.net/debian wheezy-backports main" > /etc/apt/sources.list.d/wheezy-backports.list
  12. EOF
  13. end
  14. def packages_prepare_precise
  15. return <<-EOF
  16. # ubuntu 12.04 precise does not have lz4, but it is available from a ppa:
  17. add-apt-repository -y ppa:gezakovacs/lz4
  18. EOF
  19. end
  20. def packages_debianoid
  21. return <<-EOF
  22. apt-get update
  23. # for building borgbackup and dependencies:
  24. apt-get install -y libssl-dev libacl1-dev liblz4-dev libfuse-dev fuse pkg-config
  25. apt-get install -y fakeroot build-essential git
  26. apt-get install -y python3-dev python3-setuptools
  27. # this way it works on older dists (like ubuntu 12.04) also:
  28. easy_install3 pip
  29. pip3 install virtualenv
  30. touch ~vagrant/.bash_profile ; chown vagrant ~vagrant/.bash_profile
  31. EOF
  32. end
  33. def packages_redhatted
  34. return <<-EOF
  35. yum install -y epel-release
  36. yum update -y
  37. # for building borgbackup and dependencies:
  38. yum install -y openssl-devel openssl libacl-devel libacl lz4-devel fuse-devel fuse pkgconfig
  39. usermod -a -G fuse vagrant
  40. yum install -y fakeroot gcc git patch
  41. # for building python:
  42. yum install -y zlib-devel bzip2-devel ncurses-devel readline-devel xz-devel sqlite-devel
  43. #yum install -y python-pip
  44. #pip install virtualenv
  45. touch ~vagrant/.bash_profile ; chown vagrant ~vagrant/.bash_profile
  46. EOF
  47. end
  48. def packages_darwin
  49. return <<-EOF
  50. # get osxfuse 3.0.x pre-release code from github:
  51. curl -s -L https://github.com/osxfuse/osxfuse/releases/download/osxfuse-3.0.5/osxfuse-3.0.5.dmg >osxfuse.dmg
  52. MOUNTDIR=$(echo `hdiutil mount osxfuse.dmg | tail -1 | awk '{$1="" ; print $0}'` | xargs -0 echo) \
  53. && sudo installer -pkg "${MOUNTDIR}/Extras/FUSE for OS X 3.0.5.pkg" -target /
  54. sudo chown -R vagrant /usr/local # brew must be able to create stuff here
  55. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  56. brew update
  57. brew install openssl
  58. brew install lz4
  59. brew install fakeroot
  60. brew install git
  61. touch ~vagrant/.bash_profile ; chown vagrant ~vagrant/.bash_profile
  62. EOF
  63. end
  64. def packages_freebsd
  65. return <<-EOF
  66. # for building borgbackup and dependencies:
  67. pkg install -y openssl liblz4 fusefs-libs pkgconf
  68. pkg install -y fakeroot git bash
  69. # for building python:
  70. pkg install sqlite3
  71. # make bash default / work:
  72. chsh -s bash vagrant
  73. mount -t fdescfs fdesc /dev/fd
  74. echo 'fdesc /dev/fd fdescfs rw 0 0' >> /etc/fstab
  75. # make FUSE work
  76. echo 'fuse_load="YES"' >> /boot/loader.conf
  77. echo 'vfs.usermount=1' >> /etc/sysctl.conf
  78. kldload fuse
  79. sysctl vfs.usermount=1
  80. pw groupmod operator -M vagrant
  81. touch ~vagrant/.bash_profile ; chown vagrant ~vagrant/.bash_profile
  82. EOF
  83. end
  84. def packages_openbsd
  85. return <<-EOF
  86. . ~/.profile
  87. mkdir -p /home/vagrant/borg
  88. rsync -aH /vagrant/borg/ /home/vagrant/borg/
  89. rm -rf /vagrant/borg
  90. ln -sf /home/vagrant/borg /vagrant/
  91. pkg_add bash
  92. chsh -s /usr/local/bin/bash vagrant
  93. pkg_add openssl
  94. pkg_add lz4
  95. # pkg_add fuse # does not install, sdl dependency missing
  96. pkg_add git # no fakeroot
  97. pkg_add python-3.4.2
  98. pkg_add py3-setuptools
  99. ln -sf /usr/local/bin/python3.4 /usr/local/bin/python3
  100. ln -sf /usr/local/bin/python3.4 /usr/local/bin/python
  101. easy_install-3.4 pip
  102. pip3 install virtualenv
  103. touch ~vagrant/.bash_profile ; chown vagrant ~vagrant/.bash_profile
  104. EOF
  105. end
  106. def packages_netbsd
  107. return <<-EOF
  108. hostname netbsd # the box we use has an invalid hostname
  109. PKG_PATH="ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/amd64/6.1.5/All/"
  110. export PKG_PATH
  111. pkg_add mozilla-rootcerts lz4 git bash
  112. chsh -s bash vagrant
  113. mkdir -p /usr/local/opt/lz4/include
  114. mkdir -p /usr/local/opt/lz4/lib
  115. ln -s /usr/pkg/include/lz4*.h /usr/local/opt/lz4/include/
  116. ln -s /usr/pkg/lib/liblz4* /usr/local/opt/lz4/lib/
  117. touch /etc/openssl/openssl.cnf # avoids a flood of "can't open ..."
  118. mozilla-rootcerts install
  119. # llfuse does not support netbsd
  120. pkg_add python34 py34-setuptools
  121. ln -s /usr/pkg/bin/python3.4 /usr/pkg/bin/python
  122. ln -s /usr/pkg/bin/python3.4 /usr/pkg/bin/python3
  123. easy_install-3.4 pip
  124. pip install virtualenv
  125. touch ~vagrant/.bash_profile ; chown vagrant ~vagrant/.bash_profile
  126. EOF
  127. end
  128. def install_pyenv(boxname)
  129. return <<-EOF
  130. curl -s -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
  131. echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
  132. echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
  133. echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
  134. echo 'export PYTHON_CONFIGURE_OPTS="--enable-shared"' >> ~/.bash_profile
  135. EOF
  136. end
  137. def fix_pyenv_darwin(boxname)
  138. return <<-EOF
  139. echo 'export PYTHON_CONFIGURE_OPTS="--enable-framework"' >> ~/.bash_profile
  140. EOF
  141. end
  142. def install_pythons(boxname)
  143. return <<-EOF
  144. . ~/.bash_profile
  145. pyenv install 3.2.2 # tests, 3.2(.0) and 3.2.1 deadlock, issue #221
  146. pyenv install 3.3.0 # tests
  147. pyenv install 3.4.0 # tests
  148. pyenv install 3.5.0 # tests
  149. #pyenv install 3.5.1 # binary build, use latest 3.5.x release
  150. pyenv rehash
  151. EOF
  152. end
  153. def build_sys_venv(boxname)
  154. return <<-EOF
  155. . ~/.bash_profile
  156. cd /vagrant/borg
  157. virtualenv --python=python3 borg-env
  158. EOF
  159. end
  160. def build_pyenv_venv(boxname)
  161. return <<-EOF
  162. . ~/.bash_profile
  163. cd /vagrant/borg
  164. # use the latest 3.5 release
  165. pyenv global 3.5.0
  166. pyenv virtualenv 3.5.0 borg-env
  167. ln -s ~/.pyenv/versions/borg-env .
  168. EOF
  169. end
  170. def install_borg(boxname)
  171. return <<-EOF
  172. . ~/.bash_profile
  173. cd /vagrant/borg
  174. . borg-env/bin/activate
  175. pip install -U wheel # upgrade wheel, too old for 3.5
  176. cd borg
  177. # clean up (wrong/outdated) stuff we likely got via rsync:
  178. rm -f borg/*.so borg/*.cpy*
  179. rm -f borg/{chunker,crypto,compress,hashindex,platform_linux}.c
  180. rm -rf borg/__pycache__ borg/support/__pycache__ borg/testsuite/__pycache__
  181. pip install 'llfuse<0.41' # 0.41 does not install due to UnicodeDecodeError
  182. pip install -r requirements.d/development.txt
  183. pip install -e .
  184. EOF
  185. end
  186. def install_pyinstaller(boxname)
  187. return <<-EOF
  188. . ~/.bash_profile
  189. cd /vagrant/borg
  190. . borg-env/bin/activate
  191. git clone https://github.com/pyinstaller/pyinstaller.git
  192. cd pyinstaller
  193. git checkout develop
  194. pip install -e .
  195. EOF
  196. end
  197. def install_pyinstaller_bootloader(boxname)
  198. return <<-EOF
  199. . ~/.bash_profile
  200. cd /vagrant/borg
  201. . borg-env/bin/activate
  202. git clone https://github.com/pyinstaller/pyinstaller.git
  203. cd pyinstaller
  204. git checkout python3
  205. # build bootloader, if it is not included
  206. cd bootloader
  207. python ./waf all
  208. cd ..
  209. pip install -e .
  210. EOF
  211. end
  212. def build_binary_with_pyinstaller(boxname)
  213. return <<-EOF
  214. . ~/.bash_profile
  215. cd /vagrant/borg
  216. . borg-env/bin/activate
  217. cd borg
  218. pyinstaller -F -n borg --hidden-import=logging.config borg/__main__.py
  219. EOF
  220. end
  221. def run_tests(boxname)
  222. return <<-EOF
  223. . ~/.bash_profile
  224. cd /vagrant/borg/borg
  225. . ../borg-env/bin/activate
  226. if which pyenv > /dev/null; then
  227. # for testing, use the earliest point releases of the supported python versions:
  228. pyenv global 3.2.2 3.3.0 3.4.0 3.5.0
  229. fi
  230. # otherwise: just use the system python
  231. if which fakeroot > /dev/null; then
  232. fakeroot -u tox --skip-missing-interpreters
  233. else
  234. tox --skip-missing-interpreters
  235. fi
  236. EOF
  237. end
  238. def fix_perms
  239. return <<-EOF
  240. # . ~/.profile
  241. chown -R vagrant /vagrant/borg
  242. EOF
  243. end
  244. Vagrant.configure(2) do |config|
  245. # use rsync to copy content to the folder
  246. config.vm.synced_folder ".", "/vagrant/borg/borg", :type => "rsync"
  247. # do not let the VM access . on the host machine via the default shared folder!
  248. config.vm.synced_folder ".", "/vagrant", disabled: true
  249. # fix permissions on synced folder
  250. config.vm.provision "fix perms", :type => :shell, :inline => fix_perms
  251. config.vm.provider :virtualbox do |v|
  252. #v.gui = true
  253. v.cpus = 1
  254. end
  255. # Linux
  256. config.vm.define "centos7_64" do |b|
  257. b.vm.box = "centos/7"
  258. b.vm.provider :virtualbox do |v|
  259. v.memory = 768
  260. end
  261. b.vm.provision "install system packages", :type => :shell, :inline => packages_redhatted
  262. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("centos7_64")
  263. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("centos7_64")
  264. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("centos7_64")
  265. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("centos7_64")
  266. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("centos7_64")
  267. end
  268. config.vm.define "centos6_32" do |b|
  269. b.vm.box = "centos6-32"
  270. b.vm.provision "install system packages", :type => :shell, :inline => packages_redhatted
  271. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("centos6_32")
  272. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("centos6_32")
  273. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("centos6_32")
  274. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("centos6_32")
  275. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller("centos6_32")
  276. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("centos6_32")
  277. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("centos6_32")
  278. end
  279. config.vm.define "centos6_64" do |b|
  280. b.vm.box = "centos6-64"
  281. b.vm.provider :virtualbox do |v|
  282. v.memory = 768
  283. end
  284. b.vm.provision "install system packages", :type => :shell, :inline => packages_redhatted
  285. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("centos6_64")
  286. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("centos6_64")
  287. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("centos6_64")
  288. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("centos6_64")
  289. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller("centos6_64")
  290. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("centos6_64")
  291. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("centos6_64")
  292. end
  293. config.vm.define "trusty64" do |b|
  294. b.vm.box = "ubuntu/trusty64"
  295. b.vm.provider :virtualbox do |v|
  296. v.memory = 768
  297. end
  298. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid
  299. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("trusty64")
  300. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("trusty64")
  301. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("trusty64")
  302. end
  303. config.vm.define "precise32" do |b|
  304. b.vm.box = "ubuntu/precise32"
  305. b.vm.provision "packages prepare precise", :type => :shell, :inline => packages_prepare_precise
  306. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid
  307. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("precise32")
  308. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("precise32")
  309. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("precise32")
  310. end
  311. config.vm.define "jessie64" do |b|
  312. b.vm.box = "debian/jessie64"
  313. b.vm.provider :virtualbox do |v|
  314. v.memory = 768
  315. end
  316. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid
  317. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("jessie64")
  318. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("jessie64")
  319. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("jessie64")
  320. end
  321. config.vm.define "wheezy32" do |b|
  322. b.vm.box = "puppetlabs/debian-7.8-32-nocm"
  323. b.vm.provision "packages prepare wheezy", :type => :shell, :inline => packages_prepare_wheezy
  324. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid
  325. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("wheezy32")
  326. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("wheezy32")
  327. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("wheezy32")
  328. end
  329. # OS X
  330. config.vm.define "darwin64" do |b|
  331. b.vm.box = "jhcook/yosemite-clitools"
  332. b.vm.provision "packages darwin", :type => :shell, :privileged => false, :inline => packages_darwin
  333. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("darwin64")
  334. b.vm.provision "fix pyenv", :type => :shell, :privileged => false, :inline => fix_pyenv_darwin("darwin64")
  335. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("darwin64")
  336. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("darwin64")
  337. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("darwin64")
  338. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller("darwin64")
  339. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("darwin64")
  340. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("darwin64")
  341. end
  342. # BSD
  343. config.vm.define "freebsd64" do |b|
  344. b.vm.box = "geoffgarside/freebsd-10.2"
  345. b.vm.provider :virtualbox do |v|
  346. v.memory = 768
  347. end
  348. b.vm.provision "install system packages", :type => :shell, :inline => packages_freebsd
  349. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("freebsd")
  350. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("freebsd")
  351. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("freebsd")
  352. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("freebsd")
  353. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller_bootloader("freebsd")
  354. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("freebsd")
  355. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("freebsd")
  356. end
  357. config.vm.define "openbsd64" do |b|
  358. b.vm.box = "bodgit/openbsd-5.7-amd64"
  359. b.vm.provider :virtualbox do |v|
  360. v.memory = 768
  361. end
  362. b.vm.provision "packages openbsd", :type => :shell, :inline => packages_openbsd
  363. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openbsd64")
  364. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("openbsd64")
  365. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openbsd64")
  366. end
  367. config.vm.define "netbsd64" do |b|
  368. b.vm.box = "alex-skimlinks/netbsd-6.1.5-amd64"
  369. b.vm.provider :virtualbox do |v|
  370. v.memory = 768
  371. end
  372. b.vm.provision "packages netbsd", :type => :shell, :inline => packages_netbsd
  373. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("netbsd64")
  374. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("netbsd64")
  375. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("netbsd64")
  376. end
  377. end