Vagrantfile 19 KB

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