Skip to content

1. Setup and Installation

Manoj Kumar Patra edited this page Nov 7, 2019 · 3 revisions

VirtualBox

VirtualBox is the software that actually runs the virtual machine. Download here.

Vagrant

Vagrant is the software that configures the VM and lets you share files between your host computer and the VM's filesystem. Download here.

To see the version number for vagrant, the command is vagrant --version.

Create a VagrantFile with vagrant init.

Modify VagrantFile as follows:

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

Vagrant.configure("2") do |config|
  # Configure vagrant box
  config.vm.box = "bento/ubuntu-16.04"

  # Configure vagrant box version
  config.vm.box_version = "= 2.3.5"

  # By using synced folders, Vagrant will automatically sync our files to and from the guest machine.
  # By default, Vagrant shares our project directory (the one with the Vagrantfile) to the /vagrant directory in our guest machine.
  config.vm.synced_folder ".", "/vagrant"

  # PORT FORWARDING: allows us to access a port on our own machine, but actually have all the network traffic forwarded to 
  # a specific port on the guest machine.
  config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: "127.0.0.1"

  # Work around disconnected virtual network cable.
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
  end

  config.vm.provision "shell", inline: <<-SHELL
    apt-get -qqy update

    # Work around https://github.com/chef/bento/issues/661
    # apt-get -qqy upgrade
    DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
    apt-get -qqy install make zip unzip postgresql
    apt-get -qqy install python3 python3-pip
    pip3 install --upgrade pip
    pip3 install flask packaging oauth2client redis passlib flask-httpauth
    pip3 install sqlalchemy flask-sqlalchemy psycopg2-binary bleach requests
    apt-get -qqy install python python-pip
    pip2 install --upgrade pip
    pip2 install flask packaging oauth2client redis passlib flask-httpauth
    pip2 install sqlalchemy flask-sqlalchemy psycopg2-binary bleach requests
    su postgres -c 'createuser -dRS vagrant'
    su vagrant -c 'createdb'
    su vagrant -c 'createdb news'
    su vagrant -c 'createdb forum'
    su vagrant -c 'psql forum -f /vagrant/forum/forum.sql'
    vagrantTip="[35m[1mThe shared directory is located at /vagrant\\nTo access your shared files: cd /vagrant[m"
    echo -e $vagrantTip > /etc/motd
    wget http://download.redis.io/redis-stable.tar.gz
    tar xvzf redis-stable.tar.gz
    cd redis-stable
    make
    make install
    echo "Done installing your virtual machine!"
  SHELL
end

Run vagrant up to complete installing VM.

After VM is installed, run vagrant ssh to start the VM.

NOTE: When we vagrant ssh into our machine, we're in /home/vagrant. /home/vagrant is a different directory from the synced /vagrant directory.

To exit the VM, do exit or Ctrl + D.

To reboot the VM, do vagrant up.

Clone this wiki locally