tiistai 16. kesäkuuta 2015

How to join the Django's Cookiecutter-based project and get it up and running in Ubuntu Vagrant?


Django's cookiecutter project template is really nice package of the commonly used best practices. It makes some of the boring stuff which usually consumes few days when you're creating a project.

If you have followed the Speeding up the Vagrant-instructions, you'll get the Cookiecutter project up and runnign by using these instructions.


Install Postgresql & virtualenv
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
sudo apt-get install python-virtualenv
Create a virtualenv
virtualenv venv

Create your user & the database
sudo su - postgres psql CREATE USER vagrant WITH PASSWORD 'vagrant'; CREATE DATABASE databasename OWNER vagrant; \q
exit

Add your db-details to venv/bin/activate and activate it
export DATABASE_URL=postgres://vagrant:vagrant@localhost:5432/databasename
source venv/bin/activate

Get files from the repository
git clone https://yourusername@repourl.git


Go to your repository and install OS & Python-dependencies

sudo ./install_os_dependencies.sh install
sudo ./install_os_dependencies.sh install

And you're done almost done! Run the last command and see if it works by browsing to 192.168.50.100:8000.
python manage.py runserver_plus 0.0.0.0:8000

maanantai 15. kesäkuuta 2015

Vagrant & Windows - Terrible slow - How to cure the sluggishness?


Honestly, I hate Windows CMD and from developer's point of view the Windows is no fun from many different aspect. Most of the fancy guru's are using Linux / Mac for completing their task and I don't wonder why.

Why Vagrant?

Since I got a new laptop and I don't hate Windows 8, but I still want to use familiar Linux for my development environment I decided to use vagrant instead of many other options.

Vagrant brings all the benefits of the unified dev-environment in to your Windows without sacrificing the battery life / peripheral-device support, which might happen when you'd install Linux.

Why it's better than basic Virtualbox? 
It won't install any UI for you, unlike basic virtual box installations, which makes it work much faster. Also you can install your packages from your WINDOWS CMD! <3

Installation of the Vagrant is really easy. You just install the preferred package from https://www.vagrantup.com and install virtual environment from your CMD.

WHY VAGRANT IS SO FRIKKIN SLOW????!

Everything seemed to be working nice'n easy at the begining, but after a while I grew pissed off for the unexplained sluggishness of the development.

Rebooting the Django-server toke 60 second or so... and development started to remind me more and more Java-coding than agile Python coding, no offence Java-coders.

I started digging out the issues and couldn't exactly pinpoint the cause for this problem.

Finally I found a nice article, which proposed that I should try to use Samba-file sharing instead of NFS. I didn't realize that the slow booting cycles were causer by slow file sync procedures.

Fix slow Vagrant in Windows with Samba


1st log in to Vagrant:

vagrant up && vagrant ssh

Install Samba
sudo apt-get install samba

Edit samba's config
sudo vim /etc/samba/smb.conf

Add the following pieces in the end of the smb.conf
[shared]
comment = Local Dev Server – /var/www
path = /var/www
browsable = yes
guest ok = yes
read only = no
create mask = 0777
force user = root
force group = root
#[shared] End

Restart Samba:
sudo service nmbd restart
sudo service smbd restart

Add static IP in to your Vagrant-file
config.vm.network "private_network", ip: "192.168.50.100"

Now everything should be in place and you should be able to access to \\192.168.50.100. Just copy your files there and stop slacking!