# -*- mode: ruby -*-
# Download and configure a VMware instance of Debian 7 Jessie
# Configure it for Docker runtime and development of cpppo applications.
# Assumes that a jessie64 box has been added to vagrant.
#
# Instructions for creating a custom Vagrant Debian box for VMware or VirtualBox:
#  - http://www.skoblenick.com/vagrant/creating-a-custom-box-from-scratch/
#  
# Installing and using veewee to build and package a Vagrant Debian Jessie box:
#  - https://github.com/jedi4ever/veewee/blob/master/doc/installation.md
#  - https://github.com/Mayeu/vagrant-jessie-box
#  
# Docker-based configurations)
Vagrant.configure("2") do |config|
  config.vm.box				= "jessie64"
  config.vm.provision "shell" do |s|
    # The kernel may be different than the running kernel after the upgrade!  Ubuntu Raring requires
    # software-properties-common, Precise python-software-properties to supply apt-add-repository,
    # but these have a docker dpkg; Jessie now has a docker.io package (but executable is still
    # docker) The initiating Vagrantfile's ../ directory is mounted on /home/vagrant/src_host/.
    s.inline 				= '			\
	DEBIAN_FRONTEND=noninteractive				\
        && echo -e					       "\
deb	ftp://ftp.ca.debian.org/debian		jessie		main contrib non-free\n\
\n\
deb	ftp://ftp.ca.debian.org/debian		jessie-updates	main contrib non-free\n\
\n\
deb	http://security.debian.org/		jessie/updates	main contrib non-free\n"\
            > /etc/apt/sources.list				\
        && apt-get update					\
        && apt-get -u -y dist-upgrade				\
        && apt-get install -y					\
            apt-show-versions python-pip python-dev		\
            lxc wget bsdtar curl git aufs-tools bridge-utils	\
            emacs24-nox emacs24-el screen			\
            multitail aspell zip docker.io			\
        && apt-get install -y					\
            `apt-show-versions -a				\
                | sed -ne \'s/^linux-image-\(\w\+\):\w*[[:space:]].*installed$/linux-headers-\1/p\'` \
        && addgroup vagrant staff				\
        && echo "Installing docker utilities..."		\
        && addgroup vagrant docker				\
        && sudo -u vagrant wget -q --output-document=/usr/local/bin/pipework \
                https://raw.github.com/pjkundert/pipework/master/pipework \
        && chmod 0775 /usr/local/bin/pipework			\
        && echo "Enabling IPv4 forwarding..."			\
        && sed -i -e "s/#\(net.ipv4.ip_forward\)=.*/\1=1/" /etc/sysctl.conf \
        && sysctl -w net.ipv4.ip_forward=1		        \
        && echo && echo "Login w/ vagrant ssh"			\
        '
  end
  #config.vm.network "forwarded_port", guest: 8080, host: 8080, auto_correct: true
  #config.vm.network "forwarded_port", guest: 8600, host: 8600, auto_correct: true
  config.vm.network "public_network", :bridge => 'en3: Display Ethernet', :auto_config => false
  # Mount the directory containing the cpppo image on ~/src/ 
  config.vm.synced_folder		   "../../..", "/home/vagrant/src_host", type: "nfs"
  config.vm.provider "vmware_desktop" do |v|
    v.gui 				= true
    v.vmx["memsize"]			= "4096"
    v.vmx["numvcpus"]			= "4"
  end
  config.vm.provider "vmware_fusion" do |v|
    v.gui 				= true
    v.vmx["memsize"]			= "4096"
    v.vmx["numvcpus"]			= "4"
  end
  config.vm.provider "virtualbox" do |v|
    v.gui 				= true
    v.customize ["modifyvm", :id, "--memory", "4096"]
    v.customize ["modifyvm", :id, "--cpus", "2"]
  end
end
