Skip to content

dragonfly-science/seabirds.net

Repository files navigation

This repo is the code for Seabirds.net is the website of the World Seabird Union, an umbrella organisation focused on seabird research.

It is a fairly standard Django application. Feel free to contribute by forking the code and commenting on issues.

Setup

sudo apt-get install libpg-dev postgresql
sudo apt-get install libfreetype6 libfreetype6-dev
sudo apt-get install libjpeg8 libjpeg8-dev
mkvirtualenv seabirds

Now fix Ubuntu paths to conform to PIL's weird setup assumption (more detail):

sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
pip install -r requirements.txt
sudo su postgres
psql template1

At the template1=# prompt:

CREATE USER [your username] CREATEDB;
CREATE USER seabirds;

Why?

  • The user you develop under needs to be able to create databases.
  • The seabirds user has a number of permissions assigned to it when loading a database dump from the production server.

Go back to your login, and ensure your public ssh key is in the authorised_keys of the server you are deploying to. Then run:

fab get_live_database # Download live db and load it locally
fab get_live_media    # Download all the media assets
fab get_secrets       # Get API keys etc and example sitesettings.py

Don't worry if you get an error ERROR: must be member of role "seabirds", that's just because the table belongs to you instead of the seabirds user.

get_secrets will place the production sitesettings.py in a file sitesettings_production.py. You can create your own custom settings in seabirds/sitesettings.py which might look something like this:

# Settings for seabirds.net
DEBUG = True

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'seabirds',
        'USER': 'your username',
        'HOST': 'localhost',
    }
}

Lastly, you may wish to modify your site model's domain from seabirds.net to localhost:8000. Otherwise certain URLs generated by Django may link to the live site (e.g. generated comment urls).

Deployment

fab deploy

...can be used to deploy to the development server at http://dev.seabirds.net

  • it has the same user security as the main site, but also requires HTTP authentication to see anything.

To deploy to production:

fab deploy:production

NOTE: The current seabirds setup uses media/static directories in a way that's different from Django customs. Usually media is for user uploaded content, but in this project it's been used to store everything (js/css/images).

Environment setup

Webfaction's webapp template is used for both the live and development server.

Each webapp is given a virtualenv of the same name: http://jamiecurle.co.uk/blog/webfaction-installing-virtualenv-and-virtualenvwrapper/

To setup django app to use virtualenv: http://community.webfaction.com/questions/4253/simple-virtualenv-usage-with-django

The development webapp has HTTP auth setup as specified here: http://community.webfaction.com/questions/256/apache-basic-authentication-for-mod_wsgi-inc-django-applications

Cron jobs

You need to set up the deploy_pigeons management command to run reasonably frequently to send out notification emails. Something like:

SHELL=/bin/bash
MAILTO=admin@seabirds.net
MAILFROM=admin@seabirds.net
*/5 * * * * source ~/.virtualenvs/seabirds/bin/activate && cd ~/webapps/seabirds/seabirds.net/seabirds && ./manage.py deploy_pigeons

MAILFROM is needed because of this issue.