Skip to content

Instantly share code, notes, and snippets.

@fishi0x01
Last active March 21, 2020 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fishi0x01/719c2aaab47709bb7d02 to your computer and use it in GitHub Desktop.
Save fishi0x01/719c2aaab47709bb7d02 to your computer and use it in GitHub Desktop.
Setting up a Django CI with Jenkins. Code for blog post https://fishi.devtail.io/weblog/2015/02/22/setting-django-ci-jenkins-and-git/
#!/bin/bash
# A simple django project deployment script for jenkins
BUILD_ROOT="/srv/www/django/d_project/"
MNGR=${BUILD_ROOT}"manage.py"
# source python env
echo "Sourcing python env..."
source ${BUILD_ROOT}"py-env/bin/activate"
# install requirements
pip install -r requirements.txt
# migrate model
echo "Migrate model..."
python ${MNGR} makemigrations
python ${MNGR} migrate
# collect static files
echo "Collecting static files..."
python ${MNGR} collectstatic --noinput
# restart apache - deploy Django project
echo "Restarting Apache server..."
sudo apachectl graceful
# run tests
echo "Run tests..."
python ${MNGR} jenkins --enable-coverage
# 'django-usr' running django project using python virtualenv
<VirtualHost *:80>
ServerName project.yourdomain.com
WSGIDaemonProcess django-usr python-path=/srv/www/django/d_project:/srv/www/django/d_project/py-env/lib/python2.7/site-packages
WSGIProcessGroup django-usr
WSGIScriptAlias / /srv/www/django/d_project/d_project/wsgi.py
# Project wsgi permissions
# Used for serving django pages.
<Directory /srv/www/django/d_project/d_project>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
</VirtualHost>
# Proxy requests to jenkins server on localhost:8080
# ssl connection
<VirtualHost *:443>
ServerName jenkins.yourdomain.com
SSLEngine on
SSLProxyEngine on
SSLCertificateFile /etc/ssl/certs/your.cert.pem
SSLCertificateKeyFile /etc/ssl/private/your.key.pem
ProxyPreserveHost on
ProxyRequests off
# jenkins on localhost:8080
ProxyPass / http://localhost:8080/jenkins nocanon
ProxyPassReverse / http://localhost:8080/jenkins
AllowEncodedSlashes NoDecode
<Proxy http://localhost:8080/jenkins*>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment