Vagrantfile 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # This Vagrantfile exists to test packaging. Read more about its use in the
  4. # vagrant section in TESTING.asciidoc.
  5. # Licensed to Elasticsearch under one or more contributor
  6. # license agreements. See the NOTICE file distributed with
  7. # this work for additional information regarding copyright
  8. # ownership. Elasticsearch licenses this file to you under
  9. # the Apache License, Version 2.0 (the "License"); you may
  10. # not use this file except in compliance with the License.
  11. # You may obtain a copy of the License at
  12. #
  13. # http://www.apache.org/licenses/LICENSE-2.0
  14. #
  15. # Unless required by applicable law or agreed to in writing,
  16. # software distributed under the License is distributed on an
  17. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. # KIND, either express or implied. See the License for the
  19. # specific language governing permissions and limitations
  20. # under the License.
  21. Vagrant.configure(2) do |config|
  22. config.vm.define "ubuntu-1204" do |config|
  23. config.vm.box = "elastic/ubuntu-12.04-x86_64"
  24. ubuntu_common config
  25. end
  26. config.vm.define "ubuntu-1404" do |config|
  27. config.vm.box = "elastic/ubuntu-14.04-x86_64"
  28. ubuntu_common config
  29. end
  30. config.vm.define "ubuntu-1504" do |config|
  31. config.vm.box = "elastic/ubuntu-15.04-x86_64"
  32. ubuntu_common config, extra: <<-SHELL
  33. # Install Jayatana so we can work around it being present.
  34. [ -f /usr/share/java/jayatanaag.jar ] || install jayatana
  35. SHELL
  36. end
  37. # Wheezy's backports don't contain Openjdk 8 and the backflips required to
  38. # get the sun jdk on there just aren't worth it. We have jessie for testing
  39. # debian and it works fine.
  40. config.vm.define "debian-8" do |config|
  41. config.vm.box = "elastic/debian-8-x86_64"
  42. deb_common config, 'echo deb http://http.debian.net/debian jessie-backports main > /etc/apt/sources.list.d/backports.list', 'backports'
  43. end
  44. config.vm.define "centos-6" do |config|
  45. config.vm.box = "elastic/centos-6-x86_64"
  46. rpm_common config
  47. end
  48. config.vm.define "centos-7" do |config|
  49. config.vm.box = "elastic/centos-7-x86_64"
  50. rpm_common config
  51. end
  52. config.vm.define "oel-6" do |config|
  53. config.vm.box = "elastic/oraclelinux-6-x86_64"
  54. rpm_common config
  55. end
  56. config.vm.define "oel-7" do |config|
  57. config.vm.box = "elastic/oraclelinux-7-x86_64"
  58. rpm_common config
  59. end
  60. config.vm.define "fedora-22" do |config|
  61. config.vm.box = "elastic/fedora-22-x86_64"
  62. dnf_common config
  63. end
  64. config.vm.define "opensuse-13" do |config|
  65. config.vm.box = "elastic/opensuse-13-x86_64"
  66. opensuse_common config
  67. end
  68. config.vm.define "sles-12" do |config|
  69. config.vm.box = "elastic/sles-12-x86_64"
  70. sles_common config
  71. end
  72. # Switch the default share for the project root from /vagrant to
  73. # /elasticsearch because /vagrant is confusing when there is a project inside
  74. # the elasticsearch project called vagrant....
  75. config.vm.synced_folder ".", "/vagrant", disabled: true
  76. config.vm.synced_folder ".", "/elasticsearch"
  77. config.vm.provider "virtualbox" do |v|
  78. # Give the boxes 2GB so they can run our tests if they have to.
  79. v.memory = 2048
  80. end
  81. if Vagrant.has_plugin?("vagrant-cachier")
  82. config.cache.scope = :box
  83. end
  84. config.vm.defined_vms.each do |name, config|
  85. config.options[:autostart] = false
  86. set_prompt = lambda do |config|
  87. # Sets up a consistent prompt for all users. Or tries to. The VM might
  88. # contain overrides for root and vagrant but this attempts to work around
  89. # them by re-source-ing the standard prompt file.
  90. config.vm.provision "prompt", type: "shell", inline: <<-SHELL
  91. cat \<\<PROMPT > /etc/profile.d/elasticsearch_prompt.sh
  92. export PS1='#{name}:\\w$ '
  93. PROMPT
  94. grep 'source /etc/profile.d/elasticsearch_prompt.sh' ~/.bashrc |
  95. cat \<\<SOURCE_PROMPT >> ~/.bashrc
  96. # Replace the standard prompt with a consistent one
  97. source /etc/profile.d/elasticsearch_prompt.sh
  98. SOURCE_PROMPT
  99. grep 'source /etc/profile.d/elasticsearch_prompt.sh' ~vagrant/.bashrc |
  100. cat \<\<SOURCE_PROMPT >> ~vagrant/.bashrc
  101. # Replace the standard prompt with a consistent one
  102. source /etc/profile.d/elasticsearch_prompt.sh
  103. SOURCE_PROMPT
  104. SHELL
  105. end
  106. config.config_procs.push ['2', set_prompt]
  107. end
  108. end
  109. def ubuntu_common(config, extra: '')
  110. deb_common config, 'apt-add-repository -y ppa:openjdk-r/ppa > /dev/null 2>&1', 'openjdk-r-*', extra: extra
  111. end
  112. def deb_common(config, add_openjdk_repository_command, openjdk_list, extra: '')
  113. # http://foo-o-rama.com/vagrant--stdin-is-not-a-tty--fix.html
  114. config.vm.provision "fix-no-tty", type: "shell" do |s|
  115. s.privileged = false
  116. s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
  117. end
  118. provision(config,
  119. update_command: "apt-get update",
  120. update_tracking_file: "/var/cache/apt/archives/last_update",
  121. install_command: "apt-get install -y",
  122. java_package: "openjdk-8-jdk",
  123. extra: <<-SHELL
  124. export DEBIAN_FRONTEND=noninteractive
  125. ls /etc/apt/sources.list.d/#{openjdk_list}.list > /dev/null 2>&1 ||
  126. (echo "==> Importing java-8 ppa" &&
  127. #{add_openjdk_repository_command} &&
  128. apt-get update)
  129. #{extra}
  130. SHELL
  131. )
  132. end
  133. def rpm_common(config)
  134. provision(config,
  135. update_command: "yum check-update",
  136. update_tracking_file: "/var/cache/yum/last_update",
  137. install_command: "yum install -y",
  138. java_package: "java-1.8.0-openjdk-devel")
  139. end
  140. def dnf_common(config)
  141. provision(config,
  142. update_command: "dnf check-update",
  143. update_tracking_file: "/var/cache/dnf/last_update",
  144. install_command: "dnf install -y",
  145. java_package: "java-1.8.0-openjdk-devel")
  146. if Vagrant.has_plugin?("vagrant-cachier")
  147. # Autodetect doesn't work....
  148. config.cache.auto_detect = false
  149. config.cache.enable :generic, { :cache_dir => "/var/cache/dnf" }
  150. end
  151. end
  152. def opensuse_common(config)
  153. suse_common config, ''
  154. end
  155. def suse_common(config, extra)
  156. provision(config,
  157. update_command: "zypper --non-interactive list-updates",
  158. update_tracking_file: "/var/cache/zypp/packages/last_update",
  159. install_command: "zypper --non-interactive --quiet install --no-recommends",
  160. java_package: "java-1_8_0-openjdk-devel",
  161. extra: extra)
  162. end
  163. def sles_common(config)
  164. extra = <<-SHELL
  165. zypper rr systemsmanagement_puppet
  166. zypper addrepo -t yast2 http://demeter.uni-regensburg.de/SLES12-x64/DVD1/ dvd1 || true
  167. zypper addrepo -t yast2 http://demeter.uni-regensburg.de/SLES12-x64/DVD2/ dvd2 || true
  168. zypper addrepo http://download.opensuse.org/repositories/Java:Factory/SLE_12/Java:Factory.repo || true
  169. zypper --no-gpg-checks --non-interactive refresh
  170. zypper --non-interactive install git-core
  171. SHELL
  172. suse_common config, extra
  173. end
  174. # Register the main box provisioning script.
  175. # @param config Vagrant's config object. Required.
  176. # @param update_command [String] The command used to update the package
  177. # manager. Required. Think `apt-get update`.
  178. # @param update_tracking_file [String] The location of the file tracking the
  179. # last time the update command was run. Required. Should be in a place that
  180. # is cached by vagrant-cachier.
  181. # @param install_command [String] The command used to install a package.
  182. # Required. Think `apt-get install #{package}`.
  183. # @param java_package [String] The name of the java package. Required.
  184. # @param extra [String] Extra provisioning commands run before anything else.
  185. # Optional. Used for things like setting up the ppa for Java 8.
  186. def provision(config,
  187. update_command: 'required',
  188. update_tracking_file: 'required',
  189. install_command: 'required',
  190. java_package: 'required',
  191. extra: '')
  192. # Vagrant run ruby 2.0.0 which doesn't have required named parameters....
  193. raise ArgumentError.new('update_command is required') if update_command == 'required'
  194. raise ArgumentError.new('update_tracking_file is required') if update_tracking_file == 'required'
  195. raise ArgumentError.new('install_command is required') if install_command == 'required'
  196. raise ArgumentError.new('java_package is required') if java_package == 'required'
  197. config.vm.provision "bats dependencies", type: "shell", inline: <<-SHELL
  198. set -e
  199. set -o pipefail
  200. installed() {
  201. command -v $1 2>&1 >/dev/null
  202. }
  203. install() {
  204. # Only apt-get update if we haven't in the last day
  205. if [ ! -f #{update_tracking_file} ] || [ "x$(find #{update_tracking_file} -mtime +0)" == "x#{update_tracking_file}" ]; then
  206. echo "==> Updating repository"
  207. #{update_command} || true
  208. touch #{update_tracking_file}
  209. fi
  210. echo "==> Installing $1"
  211. #{install_command} $1
  212. }
  213. ensure() {
  214. installed $1 || install $1
  215. }
  216. #{extra}
  217. installed java || install #{java_package}
  218. ensure tar
  219. ensure curl
  220. ensure unzip
  221. installed bats || {
  222. # Bats lives in a git repository....
  223. ensure git
  224. echo "==> Installing bats"
  225. git clone https://github.com/sstephenson/bats /tmp/bats
  226. # Centos doesn't add /usr/local/bin to the path....
  227. /tmp/bats/install.sh /usr
  228. rm -rf /tmp/bats
  229. }
  230. cat \<\<VARS > /etc/profile.d/elasticsearch_vars.sh
  231. export ZIP=/elasticsearch/distribution/zip/build/distributions
  232. export TAR=/elasticsearch/distribution/tar/build/distributions
  233. export RPM=/elasticsearch/distribution/rpm/build/distributions
  234. export DEB=/elasticsearch/distribution/deb/build/distributions
  235. export TESTROOT=/elasticsearch/qa/vagrant/build/testroot
  236. export BATS=/elasticsearch/qa/vagrant/src/test/resources/packaging/scripts
  237. VARS
  238. SHELL
  239. end