Created
June 26, 2013 00:25
-
-
Save icook/5863726 to your computer and use it in GitHub Desktop.
Jenkins Continuous Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup a proper path, I call my virtualenv dir "venv" and | |
# I've got the virtualenv command installed in /usr/local/bin | |
PATH=$WORKSPACE/venv/bin:/usr/local/bin:$PATH | |
# Move the source into it's own directory | |
SRC_DIR=eli5 | |
mkdir $SRC_DIR | |
mv * $SRC_DIR/ || : | |
mv .git/ $SRC_DIR/ || : | |
# Generate a new virtual enviroment | |
if [ ! -d "venv" ]; then | |
virtualenv venv | |
fi | |
. ./venv/bin/activate | |
# Populate it with the necessary packages | |
pip install -r $SRC_DIR/requirements.txt || : | |
pip install -e $SRC_DIR/. --download-cache=/tmp/$JOB_NAME | |
# stuff for testing | |
pip install jinja2 nose coverage beautifulsoup4 pyflakes clonedigger pylint pep8 | |
# drop our database | |
totems | dropdb -U eli5 -W $JOB_NAME || : | |
# recreate a fresh db | |
totems | createdb -U eli5 -W $JOB_NAME || : | |
# Setup the database connection to run to dev | |
sed -i "s#eli5:totems@localhost/eli5#eli5:totems@localhost/$JOB_NAME#g" $SRC_DIR/development.ini | |
# run our internal script to generate test data in the db | |
eli5_db reset eli5/development.ini | |
# count lines of code and output a report | |
sloccount --duplicates --wide --details $SRC_DIR/src/ | fgrep -v .svn > sloccount.sc || : | |
# Run unit tests | |
nosetests --with-xunit --verbose --where=$SRC_DIR || : | |
# Run pyflakes | |
find ./$SRC_DIR -name *.py|egrep -v '^./tests/'|xargs pyflakes > pyflakes.log || : | |
# Run pylint | |
rm -f pylint.log | |
for f in `find ./${SRC_DIR} -name *.py|egrep -v '^./tests/'`; do | |
$WORKSPACE/venv/bin/pylint --output-format=parseable --reports=y $f >> pylint.log | |
done || : | |
# Run pep8 | |
rm -f pep8.log | |
for f in `find ./${SRC_DIR} -name *.py|egrep -v '^.src/${SRC_DIR}/tests/'`; do | |
$WORKSPACE/venv/bin/pep8 --first $f >> pep8.log | |
done || : | |
python $WORKSPACE/venv/bin/clonedigger --cpd-output ./$SRC_DIR || : | |
# Setup the webserver configs and whatnot | |
mkdir $WORKSPACE/logs | |
chmod 775 $WORKSPACE/ -R || : | |
chown jenkins:www-data $WORKSPACE/ -R || : | |
cat > $WORKSPACE/nginx.conf <<-EOF | |
server { | |
listen 81; | |
root $WORKSPACE; | |
access_log $WORKSPACE/logs/access.log; | |
error_log $WORKSPACE/logs/error.log; | |
location /static/css { alias $WORKSPACE/eli5/assets/generated/css; } | |
location /static/js { alias $WORKSPACE/eli5/assets/generated/js; } | |
location /static/lib/css { alias $WORKSPACE/eli5/assets/static_lib/css; } | |
location /static/lib/js { alias $WORKSPACE/eli5/assets/static_lib/js; } | |
location /static/images { alias $WORKSPACE/eli5/assets/images; } | |
location /$JOB_NAME { | |
uwsgi_pass unix:///tmp/$JOB_NAME.sock; | |
include uwsgi_params; | |
auth_basic "Restricted"; | |
auth_basic_user_file /etc/apache2/passwd; | |
uwsgi_modifier1 30; | |
uwsgi_param SCRIPT_NAME /$JOB_NAME; | |
} | |
} | |
EOF | |
cat > $WORKSPACE/wsgi.ini <<-EOF | |
[uwsgi] | |
pythonpath = %d/venv | |
socket = /tmp/$JOB_NAME.sock | |
wsgi-file = %d/$SRC_DIR/application.wsgi | |
virtualenv = %d/venv | |
processes = 4 | |
threads = 2 | |
logto = %d/logs/wsgi.log | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment