我可以推荐this repository。
您可以对其进行修改以支持 Django 项目。
Vagrantfile 更新:
config.vm.define "web1", primary: true do |web1_config|
web1_config.ssh.forward_agent = true
# Create a private network, which allows host-only access to the machine
web1_config.vm.network "private_network", ip: "192.168.11.10"
web1_config.vm.hostname = "web1.#{domain}"
web1_config.vm.provision "shell", path: "provisioners/shell/python.setup.sh"
web1_config.vm.provision "shell", path: "provisioners/shell/application.setup.sh"
end
然后添加一个provisioners/shell/application.setup.sh文件,内容如下:
#!/bin/bash
local_user=vagrant
if [ ! -n "$(grep "^bitbucket.org " /home/$local_user/.ssh/known_hosts)" ]; then
ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts 2>/dev/null;
fi
if [[ ! -d "/home/$local_user/app" ]]; then
git clone git@bitbucket.org:czerasz/sample-django-app.git /home/$local_user/app
chown -R $local_user:$local_user /home/$local_user/app
su - $local_user -c "source /usr/local/bin/virtualenvwrapper.sh && mkvirtualenv sample-django-app-env && workon sample-django-app-env && pip install -r /home/$local_user/app/requirements.txt"
fi
更改存储库地址 (git@bitbucket.org:czerasz/sample-django-app.git) 并确保您的 git 存储库的根目录中有 requirements.txt。运行vagrant up。
Vagrant 会启动两台机器:
-
web1 与您的 django 项目
-
db1 使用 PoestgreSQL 数据库
如果您仍有问题,请将以下内容添加到您的 Vagrantfile:
web1_config.ssh.private_key_path = [ '~/.vagrant.d/insecure_private_key', '~/.ssh/bitbucket' ]
并在你的主机(你运行vagrant的机器)上执行这个命令:
ssh-add ~/.ssh/bitbucket
~/.ssh/bitbucket 是您用于 bitbucket 的 ssh 私钥。它可以是 ~/.ssh/id_rsa 或其他内容,具体取决于您的配置方式。