# Default release is 'current' config.release = 'current' config.project_name = 'nursinghomes' config.django_revision = 'XXXXX' config.newsapps_revision = 'XXXXXXX' config.database_password = 'XXXXXXX' def production(): """Production server settings""" config.settings = 'production' config.path = '/home/XXXXXX/sites/%s' % config.project_name config.fab_hosts = ['apps.chicagotribune.com'] config.fab_user = 'XXXXXX' def staging(): """Staging server settings""" config.settings = 'staging' config.path = '/home/XXXXXX/sites/%s' % config.project_name config.fab_hosts = ['beta.tribapps.com'] # will eventually want something more generic config.fab_user = 'XXXXXX' def setup(): """ Setup a fresh virtualenv, install everything we need, and fire up the database """ #using a hybrid environment -- keeping our own django in virtualenv, using the rest of the geostack, etc, from main python install #so, it's a virtualenv, but it's not a no-site-packages virtualenv. run('mkdir -p $(path); cd $(path); virtualenv env; mkdir releases; mkdir shared; mkdir logs;') clone_repo() checkout_latest() symlink_current_release() initdata() install_requirements() install_apache_conf() def deploy(): """Deploy the latest version of the site to the server and restart lighttpd""" checkout_latest() symlink_current_release() reboot() def clone_repo(): """Do initial clone of the git repo""" run('cd $(path); git clone git@tribune.unfuddle.com:tribune/$(project_name).git repository') def checkout_latest(): """Pull the latest code into the git repo and copy to a timestamped release directory""" import time config.release = time.strftime('%Y%m%d%H%M%S') run("cd $(path)/repository; git pull origin master") run('cp -R $(path)/repository $(path)/releases/$(release); rm -rf $(path)/releases/$(release)/.git*') def install_requirements(): """Install the required packages using pip""" #we don't have any packages to install to our virtualenv, they're all on the box #run('cd $(path); pip install -E env -r ./releases/$(release)/requirements.txt') run('cd $(path); svn export -r$(django_revision) http://code.djangoproject.com/svn/django/trunk/django $(path)/env/lib/python2.5/site-packages/django;') # I hate this run('cd $(path); mkdir tmp; source env/bin/activate; cd tmp; git clone git@tribune.unfuddle.com:tribune/XXXXXX.git; cd XXXXXX; git checkout $(XXXXXX_revision); python setup.py install; cd $(path); rm -Rf tmp; deactivate;') def install_apache_conf(): """Install the apache site config file""" sudo('cp $(path)/releases/current/$(project_name)/configs/$(settings)/$(project_name) /etc/apache2/sites-available/; a2ensite $(project_name);') def symlink_current_release(): """Symlink our current release, uploads and settings file""" run('cd $(path); rm releases/current; ln -s $(release) releases/current') def initdata(): """ Create the database, and load with data. We have to load the dump.sql as a superuser because it includes c functions (postgis functions). The finish_init.sql makes sure the right user owns everything """ run('echo "CREATE USER $(project_name) WITH PASSWORD \'$(database_password)\';" | psql postgres') run('createdb -O $(project_name) $(project_name) -T template_postgis') run('cd $(path)/releases/current; psql -q $(project_name) < data/psql/dump.sql') run('cd $(path)/releases/current; psql -q $(project_name) < data/psql/finish_init.sql') def load_new_data(): run('dropdb $(project_name)') run('dropuser $(project_name)') initdata() def echo_host(): run('echo $(settings); echo $(fab_hosts)') def reboot(): "Reboot Apache2 server and memcached." sudo("apache2ctl graceful") def clear_cache(): sudo("/etc/init.d/memcached restart") def shiva_the_destroyer(): """Remove all traces of the app""" run('rm -Rf $(path)') run('dropdb $(project_name)') run('dropuser $(project_name)') sudo('a2dissite $(project_name)') sudo('rm /etc/apache2/sites-available/$(project_name)') sudo("apache2ctl graceful")