Question

I'm using Vagrant and Chef solo to setup my django dev environment. Using Chef Solo I successfully install my packages (vim, git, apt, python, mysql) but then when I setup my project using pip to download/install my requirements (django, south, django-registration, etc), these ones are not correctly downloaded/found in my fresh VM.

I'm not sure if it's a location issue, but it's downloading and I have only warnings, never errors, but then it's not at the supposed location (I have another project setup exactly the same and it works, so maybe I'm missing something here...).

Here is my Vagrantfile:

Vagrant::Config.run do |config|
  config.vm.define :djangovm do |django_config|

    # Every Vagrant virtual environment requires a box to build off of.
    django_config.vm.box = "lucid64"

    # The url from where the 'config.vm.box' box will be fetched if it
    # doesn't already exist on the user's system.
    django_config.vm.box_url = "http://files.vagrantup.com/lucid64.box"

    # Forward a port from the guest to the host, which allows for outside
    # computers to access the VM, whereas host only networking does not.
    django_config.vm.forward_port 80, 8080
    django_config.vm.forward_port 8000, 8001

    # Enable provisioning with chef solo, specifying a cookbooks path (relative
    # to this Vagrantfile), and adding some recipes and/or roles.
    django_config.vm.provision :chef_solo do |chef|

     chef.json = {
        python: {
          install_method: 'source',
          version: '2.7.5',
          checksum: 'b4f01a1d0ba0b46b05c73b2ac909b1df'
        },
        mysql: {
          server_root_password: 'root',
          server_debian_password: 'root',
          server_repl_password: 'root'
        },
      }

      chef.cookbooks_path = "vagrant_resources/cookbooks"
      chef.add_recipe "apt"
      chef.add_recipe "build-essential"
      chef.add_recipe "git"
      chef.add_recipe "vim"
      chef.add_recipe "openssl"
      chef.add_recipe "mysql::client"
      chef.add_recipe "mysql::server"
      chef.add_recipe "python"

    end

    django_config.vm.provision :shell, :path => "vagrant_resources/vagrant_bootstrap.sh"
  end
end

And here the bootstrap file to download Django and continue setting up things:

#!/usr/bin/env bash

eval vagrantfile_location="~/.vagrantfile_processed"

if [ -f $vagrantfile_location ]; then
  echo "Vagrantfile already processed.  Exiting..."
  exit 0
fi

#==================================================================
# install dependencies
#==================================================================

/usr/bin/yes | pip install --upgrade pip
/usr/bin/yes | pip install --upgrade virtualenv

/usr/bin/yes | sudo apt-get install python-software-properties

#==================================================================
# set up the local dev environment
#==================================================================

if [ -f "/home/vagrant/.bash_profile" ]; then
    echo -n "removing .bash_profile for user vagrant..."
    rm /home/vagrant/.bash_profile
    echo "done!"
fi

echo -n "creating new .bash_profile for user vagrant..."
ln -s /vagrant/.bash_profile /home/vagrant/.bash_profile
source /home/vagrant/.bash_profile
echo "done!"

#==================================================================
# set up virtual env
#==================================================================
cd /vagrant;
echo -n "Creating virtualenv..."
virtualenv myquivers;
echo "done!"

echo -n "Activating virtualenv..."
source /vagrant/myquivers/bin/activate
echo "done!"

echo -n "installing project dependencies via pip..."
/usr/bin/yes | pip install -r /vagrant/myquivers/myquivers/requirements/dev.txt
echo "done!"

#==================================================================
# install front-endy things
#==================================================================

echo -n "adding node.js npm repo..."
add-apt-repository ppa:chris-lea/node.js &> /dev/null || exit 1
echo "done!"

echo -n "calling apt-get update..."
apt-get update &> /dev/null || exit 1
echo "done!"

echo -n "nodejs and npm..."
apt-get install nodejs npm &> /dev/null || exit 1
echo "done!"

echo -n "installing grunt..."
npm install -g grunt-cli &> /dev/null || exit 1
echo "done!"

echo -n "installing LESS..."
npm install -g less &> /dev/null || exit 1
echo "done!"

echo -n "installing uglify.js..."
npm install -g uglify-js &> /dev/null || exit 1
echo "done!"

#==================================================================
# cleanup
#==================================================================

echo -n "marking vagrant as processed..."
touch $vagrantfile_location
echo "done!"

My requirements dev.txt looks like this:

Django==1.5.1
Fabric==1.7.0
South==0.8.2
Pillow==2.1.0
django-less==0.7.2
paramiko==1.11.0
psycopg2==2.5.1
pycrypto==2.6
wsgiref==0.1.2
django-registration==1.0

Any idea why I can't find Django and my other things in my VM?

Was it helpful?

Solution 2

So the solution was to remove the dependency with Postgre psycopg2==2.5.1 I have in my requirements (from the setup in my other project), because here I'll be having a MySQL database instead.

OTHER TIPS

This is a whole 'nother path, but I highly recommend using Berkshelf and doing it the Berkshelf way. There's a great guide online for rolling them this way.

That is, create a cookbook as a wrapper that will do everything your script does.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top