Vagrantfile 19 KB

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