0

我正在使用 Vagrant 和 Chef solo 来设置我的 django 开发环境。使用 Chef Solo 我成功安装了我的包(vim, git, apt, python, mysql),但是当我设置我的项目使用pip下载/安装我的要求(django、south、django-registration 等)时,这些没有正确下载/在我的新鲜的虚拟机。

我不确定这是否是位置问题,但它正在下载,我只有警告,从来没有错误,但它不在假定的位置(我有另一个项目设置完全相同,它可以工作,所以也许我错过了这里的东西......)。

这是我的流浪文件:

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

这里是下载 Django 并继续设置的引导文件:

#!/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!"

我的要求 dev.txt 如下所示:

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

知道为什么我在虚拟机中找不到 Django 和其他东西吗?

4

2 回答 2

1

这是一条完整的“另一条路”,但我强烈建议使用 Berkshelf 并以Berkshelf 方式进行。网上有一个很棒的指南,可以用这种方式滚动它们。

也就是说,创建一个食谱作为包装器,它将完成您的脚本所做的一切。

于 2013-11-12T22:11:37.290 回答
0

所以解决方案是删除psycopg2==2.5.1我在我的要求中(从我的另一个项目中的设置)中对 Postgre 的依赖,因为在这里我将拥有一个 MySQL 数据库。

于 2013-11-13T04:23:51.030 回答