Just curious how people are deploying their Django projects in combination with virtualenv
- More specifically, how do you keep your production virtualenv’s synched correctly with your development machine?
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?)
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:
git log -1 --format=format:%h TREEISH. That gives usSHA_OF_THE_RELEASEgit log -1 --format=format:%h SHA_OF_THE_RELEASE requirements.txt. This spits out the short version of the hash, like1d02afcwhich is the SHA for that file for this particular release.1d02afc, a new virtualenv is created and setup withpip install -E /path/to/venv/1d02afc -r /path/to/requirements.txtpath/to/venv/1d02afc, nothing is doneThe 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 1d02afcor 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.