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

btrfs_volume = 'vagrant/host_vms/auxiliary_disks/docker_host_btrfs_volume.vdi'

Vagrant.configure("2") do |config|
  config.vm.provider :virtualbox do |provider, override|
    provider.name = "docker_host"
    override.vm.box = get_env_var_rb('docker_box') ? get_env_var_rb('docker_box') :
                     SETTINGS['GUEST_OSES'][SETTINGS['GUEST_OSES_DEFAULT']]['docker']
    provider.customize ['modifyvm', :id, '--nictype1', 'virtio']
    provider.customize ['modifyvm', :id, '--nictype2', 'virtio']
    provider.memory = get_env_var_rb('ramsize').to_i
    provider.customize ['modifyvm', :id, '--nictype1', 'virtio']
    unless File.exist?(btrfs_volume)
      provider.customize ['createhd', '--filename', btrfs_volume, '--size', get_env_var_rb('drivesize').to_i * 1024]
    end
    provider.customize ['storageattach', :id,  '--storagectl', 'SCSI', '--port', 2, '--device', 0, '--type', 'hdd', '--medium', btrfs_volume]
  end

  config.vm.define  "docker_host"

  # Configure Docker in intermediate Ubuntu host
  $config_docker_host = <<-EOS
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    apt-get update
    apt-get install -y docker-ce
    usermod -a -G docker ubuntu
    usermod -a -G docker vagrant
    ps aux | grep 'sshd:' | awk '{print $2}' | xargs kill
  EOS

  config.vm.provision "shell",
    inline: $config_docker_host,
    keep_color: true
end
