# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrant box for testing kind with cgroup v2
Vagrant.configure("2") do |config|
  # `config.vm.box = "fedora/33-cloud-base"` seems flaky,
  # so we specify the URL explicitly.
  # Mirrors can be found at here: https://admin.fedoraproject.org/mirrormanager/mirrors/Fedora/33/x86_64
  config.vm.box = "dummy"
  config.vm.box_url = "https://iad.mirror.rackspace.com/fedora/releases/33/Cloud/x86_64/images/Fedora-Cloud-Base-Vagrant-33-1.2.x86_64.vagrant-virtualbox.box"
  memory = 2048
  cpus = 2
  config.vm.provider :virtualbox do |v|
    v.memory = memory
    v.cpus = cpus
  end
  config.vm.provision "install-packages", type: "shell", run: "once" do |sh|
    sh.inline = <<~SHELL
    set -eux -o pipefail
    dnf install -y golang-go make kubernetes-client podman

    # The moby-engine package (v19.03) included in Fedora 33 does not support cgroup v2.
    # So we need to install Docker 20.10 (or later) from the upstream.
    curl -fsSL https://get.docker.com | sh
    systemctl enable --now docker
    SHELL
  end
  config.vm.provision "install-kind", type: "shell", run: "once" do |sh|
    sh.inline = <<~SHELL
    set -eux -o pipefail
    make -C /vagrant install INSTALL_DIR=/usr/local/bin
    SHELL
  end
end
