How do you manage production websites and settings with GIT?
I'm dealing with a django project that we are pushing live even as I write this. The production server is a linode and as part of the setup we have SSL and certificates and several differences from development and QA.
In my settings.py
, I have the following code:
import socket
hostname = socket.gethostname().lower().replace('-', '_').split('.')[0]
try:
exec("from %s_local_settings import *" % hostname)
except ImportError:
pass
which loads up local settings for that particular linode box. But on the same linode, we will have another instance of the project (the one we are hosting for a customer). This first instance is like advertising/demonstration/training. So, my nice little node-name hack is开发者_JAVA百科n't going to work....
How do you deal with this kind of issue in a production environment? We will have a backup linode up soon with mirrored databases, so the complexity continues to grow and I'm not sure how to easily track and maintain all the changes.
I'm using git, and I created a branch called production-www, I'm guessing as we go forward, I'll merge from master into the production-www branch and the files that are particular to this install won't be overwritten (except for the node-name file which I have no solution for right now).
Is anyone doing anything easier or smarter than this?
Commit an example settings.py file to the repository (eg: settings.py.example) then copy and edit with the real hostname for each deployment - trying to detect things like hostname, pathnames, etc can get messy fast imho.
New deployments won't clobber it since it's not in the repository, but you'll probably tell git to ignore the "settings.py" itself so you don't commit a development setting file by accident.
I have tinkered with Silk Deployment which is a Python toolkit based around Fabric that uses Git to synchronize configurations on deployments. It is intended for use with Django and it is very, very cool. Well worth a look!
精彩评论