Skip to content

Instantly share code, notes, and snippets.

@bergantine
Last active October 11, 2015 14:57
Show Gist options
  • Save bergantine/3875868 to your computer and use it in GitHub Desktop.
Save bergantine/3875868 to your computer and use it in GitHub Desktop.
Vagrantfile for Django-Newproj. #vagrant #vagrantfile #django #python

Initial setup of Vagrant Base

This step only ever needs to be done once. Once the precise64 box is installed on a system the remaining steps refer to that same box regardless of the project.

On an Apple running OS X, download and install Xcode from the Apple App Store. This is necessary to get some compilers and install Git on the host machine.

Download VirtualBox from http://www.virtualbox.org/wiki/Downloads, install the package.

Download Vagrant 2 or higher from http://downloads.vagrantup.com/, install the package.

Launch a Terminal window, check that it installed:

(host) $ which vagrant

Add a Vagrant box (we'll be using Ubuntu Precise Pangolin (12.04 LTS) 64-bit):

(host) $ vagrant box add precise64 http://files.vagrantup.com/precise64.box

Using Vagrant with This Project

Make a directory for the project and change to it, replacing <path_to> with the path to the project and <project_name> with the name of the project.

(host) $ mkdir <path_to>/<project_name> && cd $_

For example, to create a project called 'website' in your home directory:

(host) $ mkdir ~/website && cd $_

When you're all done, this directory will match up with /vagrant/ in the virtual environment. VirtualBox keeps the two directories in sync so changes to one will be made in the other.

Clone the repo, replacing <path_to_repo> with the clone URL of the repo.

(host) $ git clone <path_to_repo>

Startup Vagrant and provision the Virtual Machine.

(host) $ vagrant up

SSH in to the Virtual Machine.

(host) $ vagrant ssh 

Install the project-specific packages.

(vm) sudo pip install -r requirements/development.txt

Sync the database and migrate any migrations.

(vm) $ dj syncdb
(vm) $ dj migrate

Force compile the stylesheets (first time only).

(vm) $ compass compile myproject/static_media/stylesheets --force

Smoke Test

(vm) $ frs

Open a Web browser and navigate to http://localhost:8000. You should see the home.html template rendered.

Full Documentation

This project is a derivative of django-newproj-template and uses the Gesso frontend framework.

#!/bin/bash
# Create a directory for Chef Recipes and Cookbooks
mkdir -p ./my-recipes/cookbooks
# Download cookbooks
# apt
mkdir -p ./my-recipes/cookbooks/apt && curl -L https://github.com/opscode-cookbooks/apt/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/apt
# Build Essentials < 2.0 since Vagrant doesn't seem to be using Chef 11
# https://tickets.opscode.com/browse/COOK-4441?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel
# It looks like you could also change the version of Chef that Vagrant uses
# http://stackoverflow.com/questions/11325479/how-to-control-the-version-of-chef-that-vagrant-uses-to-provision-vms
mkdir -p ./my-recipes/cookbooks/build-essential && curl -L https://github.com/opscode-cookbooks/build-essential/archive/v1.4.4.tar.gz | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/build-essential
# sudo
mkdir -p ./my-recipes/cookbooks/sudo && curl -L https://github.com/opscode-cookbooks/sudo/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/sudo
# Open SSL
mkdir -p ./my-recipes/cookbooks/openssl && curl -L https://github.com/opscode-cookbooks/openssl/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/openssl
# PostgreSQL
mkdir -p ./my-recipes/cookbooks/postgresql && curl -L https://github.com/opscode-cookbooks/postgresql/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/postgresql
# Git
mkdir -p ./my-recipes/cookbooks/git && curl -L https://github.com/opscode-cookbooks/git/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/git
# memcached
mkdir -p ./my-recipes/cookbooks/memcached && curl -L https://github.com/opscode-cookbooks/memcached/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/memcached
# Python
mkdir -p ./my-recipes/cookbooks/python && curl -L https://github.com/comandrei/python/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/python
# zlib
mkdir -p ./my-recipes/cookbooks/zlib && curl -L https://github.com/opscode-cookbooks/zlib/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/zlib
# Python-Psycopg2
mkdir -p ./my-recipes/cookbooks/python-psycopg2 && curl -L https://github.com/jbergantine/chef-cookbook-python-psycopg2/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/python-psycopg2
# LibJpeg
mkdir -p ./my-recipes/cookbooks/libjpeg && curl -L https://github.com/jbergantine/chef-cookbook-libjpeg/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/libjpeg
# LibFreeType
mkdir -p ./my-recipes/cookbooks/libfreetype && curl -L https://github.com/jbergantine/chef-cookbook-libfreetype/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/libfreetype
# Xapian
mkdir -p ./my-recipes/cookbooks/xapian && curl -L https://github.com/jbergantine/chef-cookbook-xapian/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/xapian
# Bootstrap
mkdir -p ./my-recipes/cookbooks/chef-cookbook-djangonewproj && curl -L https://github.com/jbergantine/chef-cookbook-djangonewproj/tarball/master | tar -xz --strip-components=1 --directory=./my-recipes/cookbooks/chef-cookbook-djangonewproj
# Download the Vagrantfile
curl -L https://gist.github.com/jbergantine/3875868/raw/Vagrantfile > Vagrantfile
# Download the Readme
curl -L https://gist.github.com/jbergantine/3875868/raw/readme.md > readme.md
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
# To access our website, we can open a web browser on our workstation
# and go to http://localhost:8001.
config.vm.network "forwarded_port", guest: 8000, host: 8000
# LiveReload listens on port 35729.
# http://feedback.livereload.com/knowledgebase/articles/195869-how-to-change-the-port-number-livereload-listens-o
config.vm.network "forwarded_port", guest: 35729, host: 35729
# Enable provisioning with chef solo, specifying a cookbooks path
# (relative to this Vagrantfile), and adding some recipes and/or
# roles.
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "./my-recipes/cookbooks"
# compilers
chef.add_recipe "apt"
chef.add_recipe "build-essential"
chef.add_recipe "sudo"
# openssl is a requirement for postgresql
chef.add_recipe "openssl"
# postgresql database server
chef.add_recipe "postgresql::client"
chef.add_recipe "postgresql::server"
# git
chef.add_recipe "git"
# python, python-dev plus pip and virtualenv
chef.add_recipe "python"
chef.add_recipe "python::pip"
chef.add_recipe "python::virtualenv"
# zlib, libjpeg, and libfreetype are necessary for PIL
chef.add_recipe "zlib"
chef.add_recipe "libjpeg"
chef.add_recipe "libfreetype"
# xapian plain text search engine
chef.add_recipe "xapian"
# memcached
chef.add_recipe "memcached"
# tie it all together
chef.add_recipe "chef-cookbook-djangonewproj::virtualenv"
chef.add_recipe "chef-cookbook-djangonewproj::bash"
chef.add_recipe "chef-cookbook-djangonewproj::symlink-xapian"
chef.add_recipe "chef-cookbook-djangonewproj::symlink-pil"
chef.add_recipe "chef-cookbook-djangonewproj::postgresql"
chef.add_recipe "chef-cookbook-djangonewproj::rubygems"
chef.add_recipe "chef-cookbook-djangonewproj::start-project"
chef.add_recipe "chef-cookbook-djangonewproj::init-git"
chef.add_recipe "chef-cookbook-djangonewproj::static-media"
# Assign the password 'thisisapassword' to psql user 'postgres'
# Setup memcached
chef.json = {
:authorization => {
:sudo => {
:users => [ "vagrant" ],
:passwordless => "true"
}
},
:postgresql => {
:version => "9.1",
:listen_address => "*",
:hba => [
{ :method => "trust", :address => "0.0.0.0/0" },
{ :method => "trust", :address => "::1/0" }
],
:password => {
:postgres => "thisisapassword"
}
},
:memcached => {
:memory => '32', # in MB
:user => 'vagrant',
:port => '11211',
:listen => '127.0.0.1'
}
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment