Clean Django and Jenkins integration
February 01, 2013
Why would my production deployment require the django-jenkins INSTALLED_APP?
Essentially, it shouldn’t. And consequently, there are a few tricks which can reduce the extra code which gets included in production, whilst keeping it present for testing and continuous integration. There are two main areas of code which aren’t needed between the two environments.
The INSTALL_APPS tuple
Adding django-jenkins to the INSTALLED_APPS tuple is required to enable the manage.py functions for the jenkins integration. However, like test-related requirements (covered later), this isn’t needed in production. You can isolate out the use of your django-test app by wrapping it in an environment variable-if statement:
JENKINS = bool(os.environ.get('JENKINS', False)) if JENKINS == True: from jenkins_settings import * INSTALLED_APPS = INSTALLED_APPS + ('django_jenkins',)
This is in keeping with 12 Factor App principles, and also helps to keep your code cleaner. An alternative to setting a custom JENKINS environment variable would be to consider tying this into the DEBUG environment variable, which one would hope isn’t activated in production!
The requirements.txt file
test-requirements.txt WebTest==1.4.3 pep8==1.4.1
There you have your test-related dependencies clearly isolated from the main build code, and with relatively little extra, you can include it into your Jenkins/CI build by installing these after the main requirements. A great feature for requirements.txt includes would be to have the ability to read environment variables and install requirements based on those - I’ve raised Issue #785 on the Pip project in the hope of garnering some opinion/support for this feature.