Git deploy script

The script grab new files (after “git add”) and modified files and copy them to a new directory “deploy”.

git status | grep "modified\|new file" | awk '{print $3}' | while read file; do mkdir -p `dirname deploy/"$file"`; cp $file deploy/$file; done

Or, use this to create the deploy folder for commits done in the last 2 days: (the code may generate some error output saying certain files don’t exist, because it’s trying to copy the files you deleted in commits, they are harmless just too lazy to put check in)

git whatchanged --since "2 days ago" | grep ^: | awk '{print $6}' | sort | uniq -c | awk '{print $2}' | while read file; do mkdir -p `dirname deploy/"$file"`; cp $file deploy/$file; done

Django production server

Install

sudo apt-get install python-django libapache2-mod-wsgi python-mysqldb python-setuptools

Virtualhost

<VirtualHost *:80>
ServerName tang.local
WSGIDaemonProcess snake display-name=%{GROUP}
WSGIProcessGroup snake
WSGIScriptAlias / /mnt/host/snake/apache/django.wsgi

Alias /static  /mnt/host/snake/static
</VirtualHost>

WSGI script

import os
import sys
sys.path.append('/mnt/host')
sys.path.append('/mnt/host/snake')
os.environ['DJANGO_SETTINGS_MODULE'] = 'snake.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()