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

BOX_NAME = "ubuntu-dev"
BOX_URI = "http://files.vagrantup.com/precise64.box"
VM_IP = "192.168.33.21"
USER = "vagrant"
GOPATH = "/data/docker"
DOCKER_PATH = "#{GOPATH}/src/github.com/dotcloud/docker"
CFG_PATH = "#{DOCKER_PATH}/hack/environment"
BUILDBOT_PATH = "/data/buildbot"

Vagrant::Config.run do |config|
  # Setup virtual machine box
  config.vm.box = BOX_NAME
  config.vm.box_url = BOX_URI
  config.vm.share_folder "v-data", DOCKER_PATH, "#{File.dirname(__FILE__)}/.."
  config.vm.network :hostonly, VM_IP
  # Stop if deployment has been done
  config.vm.provision :shell, :inline => "[ ! -f /usr/bin/git ]"
  # Touch for makefile
  pkg_cmd = "touch #{DOCKER_PATH}; "
  # Install docker dependencies
  pkg_cmd << "apt-get update -qq; apt-get install -y python-software-properties; " \
    "add-apt-repository -y ppa:dotcloud/docker-golang/ubuntu; apt-get update -qq; " \
    "apt-get install -y linux-image-generic-lts-raring lxc git aufs-tools golang-stable make; " \
    "chown -R #{USER}.#{USER} #{GOPATH}; " \
    "install -m 0664 #{CFG_PATH}/bash_profile /home/#{USER}/.bash_profile"
  config.vm.provision :shell, :inline => pkg_cmd
  # Deploy buildbot CI
  pkg_cmd = "apt-get install -q -y python-dev python-pip supervisor; " \
    "pip install -q -r #{CFG_PATH}/requirements.txt; " \
    "chown #{USER}.#{USER} /data; cd /data; " \
    "#{CFG_PATH}/setup.sh #{USER} #{GOPATH} #{DOCKER_PATH} #{CFG_PATH} #{BUILDBOT_PATH}"
  config.vm.provision :shell, :inline => pkg_cmd
end
