github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/Vagrantfile (about)

     1  # Copyright (c) 2021 Red Hat, Inc.
     2  #
     3  # SPDX-License-Identifier: Apache-2.0
     4  #
     5  # This is a Vagrant configuration file.
     6  #
     7  
     8  # -*- mode: ruby -*-
     9  # vi: set ft=ruby :
    10  
    11  # Read the Kata Containers CI job from the CI_JOB environment variable.
    12  job = ENV['CI_JOB'] || ""
    13  guest_user = 'vagrant'
    14  guest_home_dir = '/home/vagrant'
    15  
    16  # All Vagrant configuration is done below. The "2" in Vagrant.configure
    17  # configures the configuration version (we support older styles for
    18  # backwards compatibility). Please don't change it unless you know what
    19  # you're doing.
    20  Vagrant.configure("2") do |config|
    21  
    22    config.trigger.before [:up, :ssh] do |trigger|
    23      if ENV['GOPATH'] == nil
    24        trigger.warn = "You must export the GOPATH environment variable"
    25        trigger.abort = true
    26      end
    27    end
    28  
    29    # By default vagrant sync the current directory. Let's disabled it because the directory
    30    # will be synced later to the proper destination.
    31    config.vm.synced_folder ".", "/vagrant", disabled:true
    32    config.vm.synced_folder ".", "#{guest_home_dir}/go/src/github.com/kata-containers/tests", type:"rsync"
    33    config.vm.synced_folder "#{ENV['GOPATH']}/src/github.com/kata-containers/kata-containers",
    34      "#{guest_home_dir}/go/src/github.com/kata-containers/kata-containers", type:"rsync"
    35  
    36    config.vm.provider "libvirt" do |lv|
    37      lv.driver = "kvm"
    38      lv.cpus = "4"
    39      lv.memory = "8192"
    40    end
    41  
    42    # Shared provision script.
    43    config.vm.provision "shell", env: {"CI_JOB" => job}, inline: <<-SHELL
    44  
    45      export GOPATH="#{guest_home_dir}/go"
    46      # The repositories were copied to the vagrant user's home by the root
    47      # user. So let's fix the files ownership.
    48      chown -R #{guest_user}:#{guest_user} "${GOPATH}"
    49      kata_tests_repo_dir="${GOPATH}/src/github.com/kata-containers/tests"
    50  
    51      env_file="#{guest_home_dir}/ci_job_env"
    52      sudo -E PATH=$PATH -H -u #{guest_user} \
    53      cat <<-EOF > ${env_file}
    54  export GOPATH="$GOPATH"
    55  export PATH="/usr/local/go/bin:\$GOPATH/bin:\$PATH"
    56  export CI="true"
    57  export CI_JOB="$CI_JOB"
    58  pushd $kata_tests_repo_dir &>/dev/null
    59  source .ci/ci_job_flags.sh
    60  popd &>/dev/null
    61  EOF
    62  
    63      source ${env_file}
    64  
    65      # Customize the .bashrc so that it will have the variables exported
    66      # after log-in.
    67      sudo -E PATH=$PATH -u #{guest_user} \
    68      echo "cd $kata_tests_repo_dir" >> #{guest_home_dir}/.bashrc
    69      sudo -E PATH=$PATH -u #{guest_user} \
    70      echo "source $env_file" >> #{guest_home_dir}/.bashrc
    71  
    72      distro=$(source /etc/os-release; echo $ID)
    73      case "$distro" in
    74        "fedora")
    75          # Fedora >= 32 Kernel comes configured with cgroup v2 by default.
    76          # This switches back to cgroup v1. It requires a reboot.
    77          sudo dnf install -y grubby
    78          sudo grubby --update-kernel=ALL --args="systemd.unified_cgroup_hierarchy=0"
    79          ;;
    80        "ubuntu")
    81          # TODO: redis-server package fails to install if IPv6 is disabled. Move this
    82          # code to the setup script.
    83          if [[ $(sysctl -n net.ipv6.conf.all.disable_ipv6) -eq 1 ]]; then
    84            sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
    85            sudo sed -i 's/\(net.ipv6.conf.all.disable_ipv6\).*/\1=0/' /etc/sysctl.conf
    86          fi
    87          ;;
    88      esac
    89  
    90      # Build the osbuilder with same distro as the host.
    91      export osbuilder_distro="$distro"
    92  
    93      cd ${kata_tests_repo_dir}
    94      sudo -E PATH=$PATH -H -u #{guest_user} bash -c '.ci/setup.sh'
    95    SHELL
    96  
    97    config.vm.define "fedora", autostart: false do |fedora|
    98      fedora.vm.box = "fedora/32-cloud-base"
    99      # Fedora is required to reboot so that the change to cgroups v1
   100      # makes effect.
   101      fedora.vm.provision "shell", reboot: true, inline: <<-SHELL
   102        echo "Need to reboot the VM"
   103      SHELL
   104    end
   105  
   106    config.vm.define "ubuntu", autostart: false do |ubuntu|
   107      ubuntu.vm.box = "generic/ubuntu2004"
   108    end
   109  end