Vagrantfile 19 KB

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