Vagrantfile 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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. mkdir -p /home/vagrant/borg
  103. rsync -aH /vagrant/borg/ /home/vagrant/borg/
  104. rm -rf /vagrant/borg
  105. ln -sf /home/vagrant/borg /vagrant/
  106. pkg_add bash
  107. chsh -s /usr/local/bin/bash vagrant
  108. pkg_add openssl
  109. pkg_add lz4
  110. pkg_add git # no fakeroot
  111. pkg_add py3-setuptools
  112. ln -sf /usr/local/bin/python3.4 /usr/local/bin/python3
  113. ln -sf /usr/local/bin/python3.4 /usr/local/bin/python
  114. easy_install-3.4 pip
  115. pip3 install virtualenv
  116. touch ~vagrant/.bash_profile ; chown vagrant ~vagrant/.bash_profile
  117. EOF
  118. end
  119. def packages_netbsd
  120. return <<-EOF
  121. hostname netbsd # the box we use has an invalid hostname
  122. PKG_PATH="ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/amd64/6.1.5/All/"
  123. export PKG_PATH
  124. pkg_add mozilla-rootcerts lz4 git bash
  125. chsh -s bash vagrant
  126. mkdir -p /usr/local/opt/lz4/include
  127. mkdir -p /usr/local/opt/lz4/lib
  128. ln -s /usr/pkg/include/lz4*.h /usr/local/opt/lz4/include/
  129. ln -s /usr/pkg/lib/liblz4* /usr/local/opt/lz4/lib/
  130. touch /etc/openssl/openssl.cnf # avoids a flood of "can't open ..."
  131. mozilla-rootcerts install
  132. pkg_add pkg-config # avoids some "pkg-config missing" error msg, even without fuse
  133. # pkg_add fuse # llfuse supports netbsd, but is still buggy.
  134. # https://bitbucket.org/nikratio/python-llfuse/issues/70/perfuse_open-setsockopt-no-buffer-space
  135. pkg_add python34 py34-setuptools
  136. ln -s /usr/pkg/bin/python3.4 /usr/pkg/bin/python
  137. ln -s /usr/pkg/bin/python3.4 /usr/pkg/bin/python3
  138. easy_install-3.4 pip
  139. pip install virtualenv
  140. touch ~vagrant/.bash_profile ; chown vagrant ~vagrant/.bash_profile
  141. EOF
  142. end
  143. def install_pyenv(boxname)
  144. return <<-EOF
  145. curl -s -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
  146. echo 'export PATH="$HOME/.pyenv/bin:/vagrant/borg:$PATH"' >> ~/.bash_profile
  147. echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
  148. echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
  149. echo 'export PYTHON_CONFIGURE_OPTS="--enable-shared"' >> ~/.bash_profile
  150. echo 'export LANG=en_US.UTF-8' >> ~/.bash_profile
  151. EOF
  152. end
  153. def fix_pyenv_darwin(boxname)
  154. return <<-EOF
  155. echo 'export PYTHON_CONFIGURE_OPTS="--enable-framework"' >> ~/.bash_profile
  156. EOF
  157. end
  158. def install_pythons(boxname)
  159. return <<-EOF
  160. . ~/.bash_profile
  161. pyenv install 3.4.0 # tests
  162. pyenv install 3.5.0 # tests
  163. pyenv install 3.5.2 # binary build, use latest 3.5.x release
  164. pyenv rehash
  165. EOF
  166. end
  167. def build_sys_venv(boxname)
  168. return <<-EOF
  169. . ~/.bash_profile
  170. cd /vagrant/borg
  171. virtualenv --python=python3 borg-env
  172. EOF
  173. end
  174. def build_pyenv_venv(boxname)
  175. return <<-EOF
  176. . ~/.bash_profile
  177. cd /vagrant/borg
  178. # use the latest 3.5 release
  179. pyenv global 3.5.2
  180. pyenv virtualenv 3.5.2 borg-env
  181. ln -s ~/.pyenv/versions/borg-env .
  182. EOF
  183. end
  184. def install_borg(boxname)
  185. return <<-EOF
  186. . ~/.bash_profile
  187. cd /vagrant/borg
  188. . borg-env/bin/activate
  189. pip install -U wheel # upgrade wheel, too old for 3.5
  190. cd borg
  191. # clean up (wrong/outdated) stuff we likely got via rsync:
  192. rm -f borg/*.so borg/*.cpy*
  193. rm -f borg/{chunker,crypto,compress,hashindex,platform_linux}.c
  194. rm -rf borg/__pycache__ borg/support/__pycache__ borg/testsuite/__pycache__
  195. pip install -r requirements.d/development.txt
  196. # by using [fuse], setup.py can handle different fuse requirements:
  197. pip install -e .[fuse]
  198. EOF
  199. end
  200. def install_borg_no_fuse(boxname)
  201. return <<-EOF
  202. . ~/.bash_profile
  203. cd /vagrant/borg
  204. . borg-env/bin/activate
  205. pip install -U wheel # upgrade wheel, too old for 3.5
  206. cd borg
  207. # clean up (wrong/outdated) stuff we likely got via rsync:
  208. rm -f borg/*.so borg/*.cpy*
  209. rm -f borg/{chunker,crypto,compress,hashindex,platform_linux}.c
  210. rm -rf borg/__pycache__ borg/support/__pycache__ borg/testsuite/__pycache__
  211. pip install -r requirements.d/development.txt
  212. pip install -e .
  213. EOF
  214. end
  215. def install_pyinstaller(boxname)
  216. return <<-EOF
  217. . ~/.bash_profile
  218. cd /vagrant/borg
  219. . borg-env/bin/activate
  220. git clone https://github.com/pyinstaller/pyinstaller.git
  221. cd pyinstaller
  222. git checkout v3.1.1
  223. pip install -e .
  224. EOF
  225. end
  226. def install_pyinstaller_bootloader(boxname)
  227. return <<-EOF
  228. . ~/.bash_profile
  229. cd /vagrant/borg
  230. . borg-env/bin/activate
  231. git clone https://github.com/pyinstaller/pyinstaller.git
  232. cd pyinstaller
  233. git checkout v3.1.1
  234. # build bootloader, if it is not included
  235. cd bootloader
  236. python ./waf all
  237. cd ..
  238. pip install -e .
  239. EOF
  240. end
  241. def build_binary_with_pyinstaller(boxname)
  242. return <<-EOF
  243. . ~/.bash_profile
  244. cd /vagrant/borg
  245. . borg-env/bin/activate
  246. cd borg
  247. pyinstaller --clean --distpath=/vagrant/borg scripts/borg.exe.spec
  248. EOF
  249. end
  250. def run_tests(boxname)
  251. return <<-EOF
  252. . ~/.bash_profile
  253. cd /vagrant/borg/borg
  254. . ../borg-env/bin/activate
  255. if which pyenv > /dev/null; then
  256. # for testing, use the earliest point releases of the supported python versions:
  257. pyenv global 3.4.0 3.5.0
  258. fi
  259. # otherwise: just use the system python
  260. if which fakeroot > /dev/null; then
  261. echo "Running tox WITH fakeroot -u"
  262. fakeroot -u tox --skip-missing-interpreters
  263. else
  264. echo "Running tox WITHOUT fakeroot -u"
  265. tox --skip-missing-interpreters
  266. fi
  267. EOF
  268. end
  269. def fix_perms
  270. return <<-EOF
  271. # . ~/.profile
  272. if id "vagrant" >/dev/null 2>&1; then
  273. chown -R vagrant /vagrant/borg
  274. else
  275. chown -R ubuntu /vagrant/borg
  276. fi
  277. EOF
  278. end
  279. Vagrant.configure(2) do |config|
  280. # use rsync to copy content to the folder
  281. config.vm.synced_folder ".", "/vagrant/borg/borg", :type => "rsync", :rsync__args => ["--verbose", "--archive", "--delete", "-z"]
  282. # do not let the VM access . on the host machine via the default shared folder!
  283. config.vm.synced_folder ".", "/vagrant", disabled: true
  284. # fix permissions on synced folder
  285. config.vm.provision "fix perms", :type => :shell, :inline => fix_perms
  286. config.vm.provider :virtualbox do |v|
  287. #v.gui = true
  288. v.cpus = 1
  289. end
  290. # Linux
  291. config.vm.define "centos7_64" do |b|
  292. b.vm.box = "centos/7"
  293. b.vm.provider :virtualbox do |v|
  294. v.memory = 768
  295. end
  296. b.vm.provision "install system packages", :type => :shell, :inline => packages_redhatted
  297. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("centos7_64")
  298. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("centos7_64")
  299. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("centos7_64")
  300. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("centos7_64")
  301. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("centos7_64")
  302. end
  303. config.vm.define "centos6_32" do |b|
  304. b.vm.box = "centos6-32"
  305. b.vm.provision "install system packages", :type => :shell, :inline => packages_redhatted
  306. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("centos6_32")
  307. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("centos6_32")
  308. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("centos6_32")
  309. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg_no_fuse("centos6_32")
  310. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("centos6_32")
  311. end
  312. config.vm.define "centos6_64" do |b|
  313. b.vm.box = "centos6-64"
  314. b.vm.provider :virtualbox do |v|
  315. v.memory = 768
  316. end
  317. b.vm.provision "install system packages", :type => :shell, :inline => packages_redhatted
  318. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("centos6_64")
  319. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("centos6_64")
  320. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("centos6_64")
  321. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg_no_fuse("centos6_64")
  322. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("centos6_64")
  323. end
  324. config.vm.define "xenial64" do |b|
  325. b.vm.box = "ubuntu/xenial64"
  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("xenial64")
  331. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("xenial64")
  332. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("xenial64")
  333. end
  334. config.vm.define "trusty64" do |b|
  335. b.vm.box = "ubuntu/trusty64"
  336. b.vm.provider :virtualbox do |v|
  337. v.memory = 768
  338. end
  339. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid
  340. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("trusty64")
  341. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("trusty64")
  342. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("trusty64")
  343. end
  344. config.vm.define "jessie64" do |b|
  345. b.vm.box = "debian/jessie64"
  346. b.vm.provider :virtualbox do |v|
  347. v.memory = 768
  348. end
  349. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid
  350. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("jessie64")
  351. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("jessie64")
  352. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("jessie64")
  353. end
  354. config.vm.define "wheezy32" do |b|
  355. b.vm.box = "boxcutter/debian7-i386"
  356. b.vm.provision "packages prepare wheezy", :type => :shell, :inline => packages_prepare_wheezy
  357. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid
  358. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("wheezy32")
  359. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("wheezy32")
  360. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("wheezy32")
  361. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("wheezy32")
  362. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller("wheezy32")
  363. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("wheezy32")
  364. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("wheezy32")
  365. end
  366. config.vm.define "wheezy64" do |b|
  367. b.vm.box = "boxcutter/debian7"
  368. b.vm.provision "packages prepare wheezy", :type => :shell, :inline => packages_prepare_wheezy
  369. b.vm.provision "packages debianoid", :type => :shell, :inline => packages_debianoid
  370. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("wheezy64")
  371. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("wheezy64")
  372. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("wheezy64")
  373. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("wheezy64")
  374. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller("wheezy64")
  375. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("wheezy64")
  376. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("wheezy64")
  377. end
  378. # OS X
  379. config.vm.define "darwin64" do |b|
  380. b.vm.box = "jhcook/yosemite-clitools"
  381. b.vm.provision "packages darwin", :type => :shell, :privileged => false, :inline => packages_darwin
  382. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("darwin64")
  383. b.vm.provision "fix pyenv", :type => :shell, :privileged => false, :inline => fix_pyenv_darwin("darwin64")
  384. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("darwin64")
  385. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("darwin64")
  386. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("darwin64")
  387. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller("darwin64")
  388. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("darwin64")
  389. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("darwin64")
  390. end
  391. # BSD
  392. config.vm.define "freebsd64" do |b|
  393. b.vm.box = "geoffgarside/freebsd-10.2"
  394. b.vm.provider :virtualbox do |v|
  395. v.memory = 768
  396. end
  397. b.vm.provision "install system packages", :type => :shell, :inline => packages_freebsd
  398. b.vm.provision "install pyenv", :type => :shell, :privileged => false, :inline => install_pyenv("freebsd")
  399. b.vm.provision "install pythons", :type => :shell, :privileged => false, :inline => install_pythons("freebsd")
  400. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_pyenv_venv("freebsd")
  401. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg("freebsd")
  402. b.vm.provision "install pyinstaller", :type => :shell, :privileged => false, :inline => install_pyinstaller_bootloader("freebsd")
  403. b.vm.provision "build binary with pyinstaller", :type => :shell, :privileged => false, :inline => build_binary_with_pyinstaller("freebsd")
  404. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("freebsd")
  405. end
  406. config.vm.define "openbsd64" do |b|
  407. b.vm.box = "kaorimatz/openbsd-5.9-amd64"
  408. b.vm.provider :virtualbox do |v|
  409. v.memory = 768
  410. end
  411. b.vm.provision "packages openbsd", :type => :shell, :inline => packages_openbsd
  412. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("openbsd64")
  413. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg_no_fuse("openbsd64")
  414. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("openbsd64")
  415. end
  416. config.vm.define "netbsd64" do |b|
  417. b.vm.box = "alex-skimlinks/netbsd-6.1.5-amd64"
  418. b.vm.provider :virtualbox do |v|
  419. v.memory = 768
  420. end
  421. b.vm.provision "packages netbsd", :type => :shell, :inline => packages_netbsd
  422. b.vm.provision "build env", :type => :shell, :privileged => false, :inline => build_sys_venv("netbsd64")
  423. b.vm.provision "install borg", :type => :shell, :privileged => false, :inline => install_borg_no_fuse("netbsd64")
  424. b.vm.provision "run tests", :type => :shell, :privileged => false, :inline => run_tests("netbsd64")
  425. end
  426. end