"Fossies" - the Fresh Open Source Software Archive

Member "elasticsearch-6.8.23/Vagrantfile" (29 Dec 2021, 13412 Bytes) of package /linux/www/elasticsearch-6.8.23-src.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # -*- mode: ruby -*-
    2 # vi: set ft=ruby :
    3 
    4 # This Vagrantfile exists to test packaging. Read more about its use in the
    5 # vagrant section in TESTING.asciidoc.
    6 
    7 # Licensed to Elasticsearch under one or more contributor
    8 # license agreements. See the NOTICE file distributed with
    9 # this work for additional information regarding copyright
   10 # ownership. Elasticsearch licenses this file to you under
   11 # the Apache License, Version 2.0 (the "License"); you may
   12 # not use this file except in compliance with the License.
   13 # You may obtain a copy of the License at
   14 #
   15 #    http://www.apache.org/licenses/LICENSE-2.0
   16 #
   17 # Unless required by applicable law or agreed to in writing,
   18 # software distributed under the License is distributed on an
   19 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   20 # KIND, either express or implied.  See the License for the
   21 # specific language governing permissions and limitations
   22 # under the License.
   23 
   24 define_opts = {
   25   autostart: false
   26 }.freeze
   27 
   28 Vagrant.configure(2) do |config|
   29 
   30   config.vm.provider 'virtualbox' do |vbox|
   31     # Give the box more memory and cpu because our tests are beasts!
   32     vbox.memory = Integer(ENV['VAGRANT_MEMORY'] || 8192)
   33     vbox.cpus = Integer(ENV['VAGRANT_CPUS'] || 4)
   34 
   35     # see https://github.com/hashicorp/vagrant/issues/9524
   36     vbox.customize ["modifyvm", :id, "--audio", "none"]
   37   end
   38 
   39   # Switch the default share for the project root from /vagrant to
   40   # /elasticsearch because /vagrant is confusing when there is a project inside
   41   # the elasticsearch project called vagrant....
   42   config.vm.synced_folder '.', '/vagrant', disabled: true
   43   config.vm.synced_folder '.', '/elasticsearch'
   44 
   45   # Expose project directory. Note that VAGRANT_CWD may not be the same as Dir.pwd
   46   PROJECT_DIR = ENV['VAGRANT_PROJECT_DIR'] || Dir.pwd
   47   config.vm.synced_folder PROJECT_DIR, '/project'
   48 
   49   'ubuntu-1404'.tap do |box|
   50     config.vm.define box, define_opts do |config|
   51       config.vm.box = 'elastic/ubuntu-14.04-x86_64'
   52       deb_common config, box
   53     end
   54   end
   55   'ubuntu-1604'.tap do |box|
   56     config.vm.define box, define_opts do |config|
   57       config.vm.box = 'elastic/ubuntu-16.04-x86_64'
   58       deb_common config, box, extra: <<-SHELL
   59         # Install Jayatana so we can work around it being present.
   60         [ -f /usr/share/java/jayatanaag.jar ] || install jayatana
   61       SHELL
   62     end
   63   end
   64   'ubuntu-1804'.tap do |box|
   65     config.vm.define box, define_opts do |config|
   66       config.vm.box = 'elastic/ubuntu-18.04-x86_64'
   67       deb_common config, box, extra: <<-SHELL
   68        # Install Jayatana so we can work around it being present.
   69        [ -f /usr/share/java/jayatanaag.jar ] || install jayatana
   70       SHELL
   71     end
   72   end
   73   # Wheezy's backports don't contain Openjdk 8 and the backflips
   74   # required to get the sun jdk on there just aren't worth it. We have
   75   # jessie and stretch for testing debian and it works fine.
   76   'debian-8'.tap do |box|
   77     config.vm.define box, define_opts do |config|
   78       config.vm.box = 'elastic/debian-8-x86_64'
   79       deb_common config, box
   80     end
   81   end
   82   'debian-9'.tap do |box|
   83     config.vm.define box, define_opts do |config|
   84       config.vm.box = 'elastic/debian-9-x86_64'
   85       deb_common config, box
   86     end
   87   end
   88   'centos-6'.tap do |box|
   89     config.vm.define box, define_opts do |config|
   90       config.vm.box = 'elastic/centos-6-x86_64'
   91       rpm_common config, box
   92     end
   93   end
   94   'centos-7'.tap do |box|
   95     config.vm.define box, define_opts do |config|
   96       config.vm.box = 'elastic/centos-7-x86_64'
   97       rpm_common config, box
   98     end
   99   end
  100   'oel-6'.tap do |box|
  101     config.vm.define box, define_opts do |config|
  102       config.vm.box = 'elastic/oraclelinux-6-x86_64'
  103       rpm_common config, box
  104     end
  105   end
  106   'oel-7'.tap do |box|
  107     config.vm.define box, define_opts do |config|
  108       config.vm.box = 'elastic/oraclelinux-7-x86_64'
  109       rpm_common config, box
  110     end
  111   end
  112   'fedora-26'.tap do |box|
  113     config.vm.define box, define_opts do |config|
  114       config.vm.box = 'elastic/fedora-26-x86_64'
  115       dnf_common config, box
  116     end
  117   end
  118   'fedora-27'.tap do |box|
  119     config.vm.define box, define_opts do |config|
  120       config.vm.box = 'elastic/fedora-27-x86_64'
  121       dnf_common config, box
  122     end
  123   end
  124   'sles-12'.tap do |box|
  125     config.vm.define box, define_opts do |config|
  126       config.vm.box = 'elastic/sles-12-x86_64'
  127       sles_common config, box
  128     end
  129   end
  130 
  131   windows_2012r2_box = ENV['VAGRANT_WINDOWS_2012R2_BOX']
  132   if windows_2012r2_box && windows_2012r2_box.empty? == false
  133     'windows-2012r2'.tap do |box|
  134       config.vm.define box, define_opts do |config|
  135         config.vm.box = windows_2012r2_box
  136         windows_common config, box
  137       end
  138     end
  139   end
  140 
  141   windows_2016_box = ENV['VAGRANT_WINDOWS_2016_BOX']
  142   if windows_2016_box && windows_2016_box.empty? == false
  143     'windows-2016'.tap do |box|
  144       config.vm.define box, define_opts do |config|
  145         config.vm.box = windows_2016_box
  146         windows_common config, box
  147       end
  148     end
  149   end
  150 end
  151 
  152 def deb_common(config, name, extra: '')
  153   # http://foo-o-rama.com/vagrant--stdin-is-not-a-tty--fix.html
  154   config.vm.provision 'fix-no-tty', type: 'shell' do |s|
  155       s.privileged = false
  156       s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile"
  157   end
  158   linux_common(
  159     config,
  160     name,
  161     update_command: 'apt-get update',
  162     update_tracking_file: '/var/cache/apt/archives/last_update',
  163     install_command: 'apt-get install -y',
  164     extra: extra
  165   )
  166 end
  167 
  168 def rpm_common(config, name)
  169   linux_common(
  170     config,
  171     name,
  172     update_command: 'yum check-update',
  173     update_tracking_file: '/var/cache/yum/last_update',
  174     install_command: 'yum install -y'
  175   )
  176 end
  177 
  178 def dnf_common(config, name)
  179   # Autodetect doesn't work....
  180   if Vagrant.has_plugin?('vagrant-cachier')
  181     config.cache.auto_detect = false
  182     config.cache.enable :generic, { :cache_dir => '/var/cache/dnf' }
  183   end
  184   linux_common(
  185     config,
  186     name,
  187     update_command: 'dnf check-update',
  188     update_tracking_file: '/var/cache/dnf/last_update',
  189     install_command: 'dnf install -y',
  190     install_command_retries: 5
  191   )
  192 end
  193 
  194 def suse_common(config, name, extra: '')
  195   linux_common(
  196     config,
  197     name,
  198     update_command: 'zypper --non-interactive list-updates',
  199     update_tracking_file: '/var/cache/zypp/packages/last_update',
  200     install_command: 'zypper --non-interactive --quiet install --no-recommends',
  201     extra: extra
  202   )
  203 end
  204 
  205 def sles_common(config, name)
  206   extra = <<-SHELL
  207     zypper rr systemsmanagement_puppet puppetlabs-pc1
  208     zypper --non-interactive install git-core
  209   SHELL
  210   suse_common config, name, extra: extra
  211 end
  212 
  213 # Configuration needed for all linux boxes
  214 # @param config Vagrant's config object. Required.
  215 # @param name [String] The box name. Required.
  216 # @param update_command [String] The command used to update the package
  217 #   manager. Required. Think `apt-get update`.
  218 # @param update_tracking_file [String] The location of the file tracking the
  219 #   last time the update command was run. Required. Should be in a place that
  220 #   is cached by vagrant-cachier.
  221 # @param install_command [String] The command used to install a package.
  222 #   Required. Think `apt-get install #{package}`.
  223 # @param install_command_retries [Integer] Number of times to retry
  224 #   a failed install command
  225 # @param extra [String] Additional script to run before installing
  226 #   dependencies
  227 #
  228 def linux_common(config,
  229                  name,
  230                  update_command: 'required',
  231                  update_tracking_file: 'required',
  232                  install_command: 'required',
  233                  install_command_retries: 0,
  234                  extra: '')
  235 
  236   raise ArgumentError, 'update_command is required' if update_command == 'required'
  237   raise ArgumentError, 'update_tracking_file is required' if update_tracking_file == 'required'
  238   raise ArgumentError, 'install_command is required' if install_command == 'required'
  239 
  240   if Vagrant.has_plugin?('vagrant-cachier')
  241     config.cache.scope = :box
  242   end
  243 
  244   config.vm.provision 'markerfile', type: 'shell', inline: <<-SHELL
  245     touch /etc/is_vagrant_vm
  246     touch /is_vagrant_vm # for consistency between linux and windows
  247   SHELL
  248 
  249   # This prevents leftovers from previous tests using the
  250   # same VM from messing up the current test
  251   config.vm.provision 'clean es installs in tmp', run: 'always', type: 'shell', inline: <<-SHELL
  252     rm -rf /tmp/elasticsearch*
  253   SHELL
  254 
  255   sh_set_prompt config, name
  256   sh_install_deps(
  257     config,
  258     update_command,
  259     update_tracking_file,
  260     install_command,
  261     install_command_retries,
  262     extra
  263   )
  264 end
  265 
  266 # Sets up a consistent prompt for all users. Or tries to. The VM might
  267 # contain overrides for root and vagrant but this attempts to work around
  268 # them by re-source-ing the standard prompt file.
  269 def sh_set_prompt(config, name)
  270   config.vm.provision 'set prompt', type: 'shell', inline: <<-SHELL
  271       cat \<\<PROMPT > /etc/profile.d/elasticsearch_prompt.sh
  272 export PS1='#{name}:\\w$ '
  273 PROMPT
  274       grep 'source /etc/profile.d/elasticsearch_prompt.sh' ~/.bashrc |
  275         cat \<\<SOURCE_PROMPT >> ~/.bashrc
  276 # Replace the standard prompt with a consistent one
  277 source /etc/profile.d/elasticsearch_prompt.sh
  278 SOURCE_PROMPT
  279       grep 'source /etc/profile.d/elasticsearch_prompt.sh' ~vagrant/.bashrc |
  280         cat \<\<SOURCE_PROMPT >> ~vagrant/.bashrc
  281 # Replace the standard prompt with a consistent one
  282 source /etc/profile.d/elasticsearch_prompt.sh
  283 SOURCE_PROMPT
  284   SHELL
  285 end
  286 
  287 def sh_install_deps(config,
  288                     update_command,
  289                     update_tracking_file,
  290                     install_command,
  291                     install_command_retries,
  292                     extra)
  293   config.vm.provision 'install dependencies', type: 'shell', inline:  <<-SHELL
  294     set -e
  295     set -o pipefail
  296 
  297     # Retry install command up to $2 times, if failed
  298     retry_installcommand() {
  299       n=0
  300       while true; do
  301         #{install_command} $1 && break
  302         let n=n+1
  303         if [ $n -ge $2 ]; then
  304           echo "==> Exhausted retries to install $1"
  305           return 1
  306         fi
  307         echo "==> Retrying installing $1, attempt $((n+1))"
  308         # Add a small delay to increase chance of metalink providing updated list of mirrors
  309         sleep 5
  310       done
  311     }
  312 
  313     installed() {
  314       command -v $1 2>&1 >/dev/null
  315     }
  316 
  317     install() {
  318       # Only apt-get update if we haven't in the last day
  319       if [ ! -f #{update_tracking_file} ] || [ "x$(find #{update_tracking_file} -mtime +0)" == "x#{update_tracking_file}" ]; then
  320         echo "==> Updating repository"
  321         #{update_command} || true
  322         touch #{update_tracking_file}
  323       fi
  324       echo "==> Installing $1"
  325       if [ #{install_command_retries} -eq 0 ]
  326       then
  327         #{install_command} $1
  328       else
  329         retry_installcommand $1 #{install_command_retries}
  330       fi
  331     }
  332 
  333     ensure() {
  334       installed $1 || install $1
  335     }
  336 
  337     #{extra}
  338 
  339     installed java || {
  340       echo "==> Java is not installed"
  341       return 1
  342     }
  343     cat \<\<JAVA > /etc/profile.d/java_home.sh
  344 if [ -z "\\\$JAVA_HOME" ]; then
  345   export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
  346 fi
  347 JAVA
  348     ensure tar
  349     ensure curl
  350     ensure unzip
  351     ensure rsync
  352 
  353     installed bats || {
  354       # Bats lives in a git repository....
  355       ensure git
  356       echo "==> Installing bats"
  357       git clone https://github.com/sstephenson/bats /tmp/bats
  358       # Centos doesn't add /usr/local/bin to the path....
  359       /tmp/bats/install.sh /usr
  360       rm -rf /tmp/bats
  361     }
  362 
  363     cat \<\<VARS > /etc/profile.d/elasticsearch_vars.sh
  364 export ZIP=/elasticsearch/distribution/zip/build/distributions
  365 export TAR=/elasticsearch/distribution/tar/build/distributions
  366 export RPM=/elasticsearch/distribution/rpm/build/distributions
  367 export DEB=/elasticsearch/distribution/deb/build/distributions
  368 export BATS=/project/build/bats
  369 export BATS_UTILS=/project/build/packaging/bats/utils
  370 export BATS_TESTS=/project/build/packaging/bats/tests
  371 export PACKAGING_ARCHIVES=/project/build/packaging/archives
  372 export PACKAGING_TESTS=/project/build/packaging/tests
  373 VARS
  374     cat \<\<SUDOERS_VARS > /etc/sudoers.d/elasticsearch_vars
  375 Defaults   env_keep += "ZIP"
  376 Defaults   env_keep += "TAR"
  377 Defaults   env_keep += "RPM"
  378 Defaults   env_keep += "DEB"
  379 Defaults   env_keep += "BATS"
  380 Defaults   env_keep += "BATS_UTILS"
  381 Defaults   env_keep += "BATS_TESTS"
  382 Defaults   env_keep += "PACKAGING_ARCHIVES"
  383 Defaults   env_keep += "PACKAGING_TESTS"
  384 Defaults   env_keep += "JAVA_HOME"
  385 SUDOERS_VARS
  386     chmod 0440 /etc/sudoers.d/elasticsearch_vars
  387   SHELL
  388 end
  389 
  390 def windows_common(config, name)
  391   config.vm.provision 'markerfile', type: 'shell', inline: <<-SHELL
  392     $ErrorActionPreference = "Stop"
  393     New-Item C:/is_vagrant_vm -ItemType file -Force | Out-Null
  394   SHELL
  395 
  396   config.vm.provision 'set prompt', type: 'shell', inline: <<-SHELL
  397     $ErrorActionPreference = "Stop"
  398     $ps_prompt = 'function Prompt { "#{name}:$($ExecutionContext.SessionState.Path.CurrentLocation)>" }'
  399     $ps_prompt | Out-File $PsHome/Microsoft.PowerShell_profile.ps1
  400   SHELL
  401 
  402   config.vm.provision 'set env variables', type: 'shell', inline: <<-SHELL
  403     $ErrorActionPreference = "Stop"
  404     [Environment]::SetEnvironmentVariable("PACKAGING_ARCHIVES", "C:/project/build/packaging/archives", "Machine")
  405     [Environment]::SetEnvironmentVariable("PACKAGING_TESTS", "C:/project/build/packaging/tests", "Machine")
  406   SHELL
  407 end