Django和VirtualEnv开发/部署最佳实践 [英] Django and VirtualEnv Development/Deployment Best Practices

查看:132
本文介绍了Django和VirtualEnv开发/部署最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是好奇人们如何与virtualenv一起部署他们的Django项目

Just curious how people are deploying their Django projects in combination with virtualenv


  • 更具体地说,你如何使生产virtualenv正确同步与您的开发机器?

我使用git为scm,但我没有我的virtualenv里面的git repo - 最好使用点冻结,然后使用冻结输出在服务器上重新创建环境? (如果你这样做,你可以描述这些步骤 - 我在解冻过程中找到很少的好的文档 - 像 pip install -r freeze_output.txt 可能吗? )

I use git for scm but I don't have my virtualenv inside the git repo - should I, or is it best to use the pip freeze and then re-create the environment on the server using the freeze output? (If you do this, could you please describe the steps - I am finding very little good documentation on the unfreezing process - is something like pip install -r freeze_output.txt possible?)

推荐答案

我刚刚在工作中使用pip,Fabric和git设置了这样的东西。流程基本上是这样的,并且从这个脚本

I just set something like this up at work using pip, Fabric and git. The flow is basically like this, and borrows heavily from this script:


  1. 在我们的源代码树中,我们维护一个require.txt文件。我们将手动维护。

  2. 当我们执行新版本时,Fabric脚本将根据我们传递的任何树状结构创建归档。

  3. Fabric会找到我们正在部署的SHA,使用 git log -1 --format = format:%h TREEISH 。这将给我们 SHA_OF_THE_RELEASE

  4. Fabric将获取我们的需求文件的最后一个SHA,具有 git log -1 - -format = format:%h SHA_OF_THE_RELEASE requirements.txt 。这散发出了散文的简短版本,如 1d02afc ,这是该特定版本的该文件的SHA。

  5. 然后,脚本将查看我们的virtualenvs存储在远程主机上的目录。

  1. In our source tree, we maintain a requirements.txt file. We'll maintain this manually.
  2. When we do a new release, the Fabric script creates an archive based on whatever treeish we pass it.
  3. Fabric will find the SHA for what we're deploying with git log -1 --format=format:%h TREEISH. That gives us SHA_OF_THE_RELEASE
  4. Fabric will get the last SHA for our requirements file with git log -1 --format=format:%h SHA_OF_THE_RELEASE requirements.txt. This spits out the short version of the hash, like 1d02afc which is the SHA for that file for this particular release.
  5. The Fabric script will then look into a directory where our virtualenvs are stored on the remote host(s).

  1. 如果没有名为 1d02afc 的目录,则会创建一个新的virtualenv并使用 pip install -E / path / to / venv / 1d02afc -r /path/to/requirements.txt

  2. 如果现有的路径/到/ venv / 1d02afc ,没有任何事情完成

  1. If there is not a directory named 1d02afc, a new virtualenv is created and setup with pip install -E /path/to/venv/1d02afc -r /path/to/requirements.txt
  2. If there is an existing path/to/venv/1d02afc, nothing is done


这个小魔术的一部分是通过任何你想要的git的树,并让它做包装(从Fabric)。通过使用 git存档my-branch git archive 1d02afc 或其他任何东西,我保证获得正确的包安装在我的远程机器上。

The little magic part of this is passing whatever tree-ish you want to git, and having it do the packaging (from Fabric). By using git archive my-branch, git archive 1d02afc or whatever else, I'm guaranteed to get the right packages installed on my remote machines.

我去了这条路线,因为如果软件包在发布之间没有改变,我真的不想有额外的虚拟机浮动。我也不喜欢在我自己的源代码树中使用我依赖的实际包的想法。

I went this route since I really didn't want to have extra virtuenvs floating around if the packages hadn't changed between release. I also don't like the idea of having the actual packages I depend on in my own source tree.

这篇关于Django和VirtualEnv开发/部署最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆