Skip to content
espenja edited this page May 11, 2013 · 18 revisions

What is Vagrant?

Vagrant is a VirtualBox-wrapper that automatically installs, configures and provides network and sharing access to the virtual machine.

Stolen from Why Vagrant?

Vagrant will isolate dependencies and their configuration within a single disposable, consistent environment, without sacrificing any of the tools you're used to working with (editors, browsers, debuggers, etc.). Once you or someone else creates a single Vagrantfile, you just need to vagrant up and everything is installed and configured for you to work. Other members of your team create their development environments from the same configuration, so whether you're working on Linux, Mac OS X, or Windows, all your team members are running code in the same environment, against the same dependencies, all configured the same way. Say goodbye to "works on my machine" bugs.

The benefit of using Vagrant: all you basically have to do in order to have a development environment ready to go with OnlineWeb4, is running two commands each time you need to set up a new environment. You don't have to manually install many packages and figuring out what the errors you encounter are.

Preparations

If you are running Windows, or any other OS where git config --global core.autocrlf true seems like a good idea - revert it to git config --global core.autocrlf false right now. If you are using a decent editor, it can handle UNIX line breaks just fine. If not, get a decent editor.

Having this set to true can potentially cause you to commit the entire project with non-UNIX-styled line breaks.

Install VirtualBox

Depending on your OS, you may need to put VirtualBox's binary files on your environment path.

Install Vagrant

git clone [email protected]:dotKom/onlineweb4.git

Place yourself in the folder containing the git project, and type vagrant up

The virtual machine will then proceed installing all packages required by OnlineWeb4.

Setting up your virtual environment

Place yourself in the folder containing the git project, and type vagrant ssh. If you want you can also ssh to the machine with your regular way of ssh-ing. Username and password are both vagrant

mkvirtualenv onlineweb4

Making sure autocrlf in your git config is set to false

The virtual machine is configured to allow sharing of folders between the guest and host OS. This folder is located at /vagrant

cd /vagrant

First make sure that the previously mentioned git config --global core.autocrlf false in your host OS is correct

git status. If this returns a list of all of the files in the project, you have done something wrong on your host OS.

Installing required python packages for OnlineWeb4

pip install -r requirements.txt


Things to know about your Vagrant VM

localhost on your VM defaults to the loopback-device. You must therefor find your eth0 ip address by typing ip a

Run your django-server with python manage.py runserver <ip>:8000

  • To reach your standard python manage.py runserver running on port 8080
  • Open your browser on localhost:8080

All of these commands are run on the host OS in your project directory.

  • To start your vm, type vagrant up
  • To suspend your vm, type vagrant suspend
  • To shut down your vm, type vagrant halt
  • To reload your config, type vagrant reload

The current config will set up port-forwarding for you. Port 22 is forwarded to 2222, and 8080 to 8080 on your host OS.

  • You can ssh into your machine with:
  • vagrant ssh
  • ssh vagrant@localhost:2222