Skip to content
Snippets Groups Projects
Vagrantfile 2.44 KiB
# Vagrantfile for a test 3-node autoradio cluster.
#
# By default it will pull autoradio packages from the public
# repository. Set the environment variable LOCAL to a non-empty value
# if you want to use local packages, in which case the 'etcd' and
# 'autoradio' packages should be placed in the same directory as this
# file.
#
# If you have an APT proxy available, you can set the APT_PROXY environment
# variable to its host:port address, and the VMs will use it to retrieve
# Debian packages. This will make the setup step faster.

API_VERSION = "2"

# Note: we shouldn't need to create a host entry for 'etcd' but it is
# faster to set up the cluster this way.
$setup_host_file = <<SCRIPT
cat >/etc/hosts <<EOF
127.0.0.1 localhost
192.168.50.2 node1.autora.dio etcd.autora.dio node1
192.168.50.3 node2.autora.dio node2
192.168.50.4 node3.autora.dio node3
EOF
SCRIPT

# Static configuration for etcd.
$setup_etcd = <<SCRIPT
cat >/etc/default/etcd <<EOF
START=1
ETCD_INITIAL_CLUSTER_STATE=new
ETCD_INITIAL_CLUSTER=node1=http://192.168.50.2:2380,node2=http://192.168.50.3:2380,node3=http://192.168.50.4:2380
EOF
SCRIPT

# Setup apt proxy.
$setup_apt_proxy = <<SCRIPT
cat >/etc/apt/apt.conf.d/000apt-proxy <<EOF
Acquire::http::Proxy "http://#{ENV['APT_PROXY']}/";
Acquire::http::Pipeline-Depth "23";
EOF
SCRIPT

Vagrant.configure(API_VERSION) do |config|
  config.vm.box = "wheezy"
  config.vm.box_url = "http://www.incal.net/ale/debian-wheezy-64.box"

  config.vm.provision "shell", inline: $setup_host_file

  if !ENV['APT_PROXY'].nil?
    config.vm.provision "shell", inline: $setup_apt_proxy
  end

  config.vm.provision "shell" do |s|
    if ENV['LOCAL'].nil?
      s.path = "bootstrap.sh"
    else
      s.path = "bootstrap-local.sh"
    end
    s.args = "autora.dio"
  end

  config.vm.define "node1" do |m|
    m.vm.hostname = "node1"
    m.vm.network "private_network", ip: "192.168.50.2"
    m.vm.provision "shell", inline: $setup_etcd
  end

  config.vm.define "node2" do |m|
    m.vm.hostname = "node2"
    m.vm.network "private_network", ip: "192.168.50.3"
    m.vm.provision "shell", inline: $setup_etcd
  end

  config.vm.define "node3" do |m|
    m.vm.hostname = "node3"
    m.vm.network "private_network", ip: "192.168.50.4"
    m.vm.provision "shell", inline: $setup_etcd

    # Create a test mountpoint.
    m.vm.provision "shell",
      inline: "sleep 3 && radioctl create-mount /stream.ogg"

    # Start streaming.
    m.vm.provision "shell", path: "start-source"
  end

end