|
| 1 | +# Codespeed Example instance |
| 2 | + |
| 3 | +Codespeed uses the Web framework [Django](http://djangoproject.com/). To get a |
| 4 | +Codespeed instance running you need to set up a Django Project. This directory |
| 5 | +is just such a project for your reference and a jump start to create your own. |
| 6 | + |
| 7 | +## For the impatient |
| 8 | + |
| 9 | +Warning: It is recommended to use [virtualenv](http://pypi.python.org/pypi/virtualenv) to avoid installing |
| 10 | +stuff on the root path of your operating system. |
| 11 | +However, it works also this way and might be desired in production |
| 12 | +environments. |
| 13 | + |
| 14 | +### Testing with the built-in Development Server |
| 15 | +That will give you *just* the Django development server version. Please |
| 16 | +refer to *Installing for Production* for serious installations. |
| 17 | + |
| 18 | +It is assumed you are in the root directory of the Codespeed software. |
| 19 | + |
| 20 | +1. Install the Python pip module |
| 21 | + `which pip >/dev/null || easy_install pip` |
| 22 | + (You might be required to use sudo) |
| 23 | +2. You *must* copy the `sample_project` directory to your project. (Prevents updates on |
| 24 | + git tracked files in the future.) Let's call it speedcenter |
| 25 | + `cp -r sample_project speedcenter` |
| 26 | +3a. (When configuring your own project) `pip install codespeeed` |
| 27 | +3b. (For Codespeed development) Install Django and other dependencies using pip |
| 28 | + `pip install -r requirements.txt`. This will not install codespeed itself, as we want runserver to only "see" the local codespeed copy |
| 29 | +4. Add codespeed to your Python path |
| 30 | + Either |
| 31 | + `export PYTHONPATH=../:$PYTHONPATH` |
| 32 | + or |
| 33 | + `ln -s ./codespeed ./sample_project` |
| 34 | +5. Initialise the Django Database |
| 35 | + `python manage.py syncdb` |
| 36 | + (Yes, add a superuser.) |
| 37 | + `python manage.py migrate` |
| 38 | + Optionally, you may want to load the fixture data for a try |
| 39 | + `python manage.py loaddata ../codespeed/fixtures/testdata.json` |
| 40 | +6. Finally, start the Django development server. |
| 41 | + `python manage.py runserver` |
| 42 | +7. Enjoy. |
| 43 | + `python -m webbrowser -n http://localhost:8000` |
| 44 | + |
| 45 | +## Installing for production |
| 46 | +There are many choices to get Django Web apps served. It all depends on |
| 47 | +your preferences and existing set up. Two options are shown. Please do |
| 48 | +not hesitate to consult a search engine to tune your set-up. |
| 49 | + |
| 50 | +### NGINX + GUNICORN: Easy as manage.py runserver |
| 51 | +Assumed you have a [Debian](http://www.debian.org) like system. |
| 52 | + |
| 53 | +1. Follow the steps from the development server set-up up to the the 6th step (database init). |
| 54 | +2. Install [nginx](http://nginx.net/) and [gunicorn](http://gunicorn.org/) |
| 55 | + `sudo apt-get install nginx gunicorn` |
| 56 | +3. Tune /etc/nginx/sites-enabled/default to match |
| 57 | + deploy/nginx.default-site.conf |
| 58 | + (Hint: See diff /etc/nginx/sites-enabled/default deploy/nginx.default-site.conf |
| 59 | + for changes) |
| 60 | + Note, the sitestatic dir needs to point to your speedcenter/sitestatic dir! |
| 61 | +4. Restart nginx |
| 62 | + /etc/init.d/nginx restart` |
| 63 | +5. Prepare static files |
| 64 | + `cd /path/to/speedcenter/` |
| 65 | + `python ./manage.py collectstatic` |
| 66 | +6. Add 'gunicorn' to your INSTALLED_APPS in settings.py |
| 67 | + INSTALLED_APPS = ( |
| 68 | + 'django.contrib.auth', |
| 69 | + [...] |
| 70 | + 'south', |
| 71 | + 'gunicorn' |
| 72 | + ) |
| 73 | +6. Run speedcenter by |
| 74 | + `python ./manage.py run_gunicorn` |
| 75 | +7. Check your new speedcenter site! Great! But wait, who runs gunicorn after the |
| 76 | + terminal exits? |
| 77 | + There are several options like upstart, runit, or supervisor. |
| 78 | + Let's go with supervisor: |
| 79 | + 1. <Ctrl>+<c> to exit gunicorn |
| 80 | + 2. `apt-get install supervisor` |
| 81 | + 3. `cp deploy/supervisor-speedcenter.conf /etc/supervisor/conf.d/speedcenter.conf` |
| 82 | + 4. `$EDITOR /etc/supervisor/conf.d/speedcenter.conf #adjust the path` |
| 83 | + 5. `supervisorctl update` |
| 84 | + 6. `supervisorctl status` |
| 85 | + speedcenter RUNNING pid 2036, uptime 0:00:05 |
| 86 | +8. Warning: You may find another way to run gunicorn using `gunicorn_django`. That might |
| 87 | + have a shebang of `#!/usr/bin/python` bypassing your virtualenv. Run it out of your |
| 88 | + virtualenv by `python $(which gunicorn_django)` |
| 89 | + |
| 90 | +### Good old Apache + mod_wsgi |
| 91 | +If you don't like surprises and are not into experimenting go with the old work horse. |
| 92 | +Assumed you have a [Debian](http://www.debian.org) like system. |
| 93 | + |
| 94 | +1. Follow the steps from the development server set-up |
| 95 | +2. Prepare static files |
| 96 | + `cd /path/to/speedcenter/` |
| 97 | + `python ./manage.py collectstatic` |
| 98 | +3. Install apache and mod_wsgi |
| 99 | + `apt-get install apache2 libapache2-mod-wsgi` |
| 100 | +4. Copy deploy/apache-speedcenter.conf |
| 101 | + `cp deploy/apache-speedcenter.conf /etc/apache2/sites-available/speedcenter.conf` |
| 102 | +5. Edit /etc/apache2/sites-available/speedcenter.conf to match your needs |
| 103 | +6. Enable the new vhost |
| 104 | + `a2ensite speedcenter.conf` |
| 105 | +7. Restart apache |
| 106 | + `/etc/init.d/apache2 restart` |
| 107 | +8. Check your new vhost. |
| 108 | + |
| 109 | +## Customisations |
| 110 | + |
| 111 | +### Using your own Templates |
| 112 | +Just edit your very own Django templates in `speedcenter/templates`. A good |
| 113 | +start is `codespeed/base.html` the root of all templates. |
| 114 | + |
| 115 | +If you need to change the codespeed templates: |
| 116 | +1. Copy the templates from the codespeed module into your Django project folder. |
| 117 | + `cp -r codespeed/templates/codespeed speedcenter/templates/` |
| 118 | +2. Edit the templates in speedcenter/templates/codespeed/*html |
| 119 | +Please, also refer to the [Django template docu] |
| 120 | +(http://docs.djangoproject.com/en/1.4/ref/templates/) |
| 121 | + |
| 122 | +### Changing the URL Scheme |
| 123 | +If you don't want to have your speedcenter in the root url you can change urls.py. |
| 124 | +Comment (add a '#' at the beginning) line number 25 `(r'^', include('cod...` |
| 125 | +and uncomment the next line `(r'^speed/', include('cod...` (Note, Python is |
| 126 | +picky about indentation). |
| 127 | +Please, also refer to the [Django URL dispatcher docu] |
| 128 | +(http://docs.djangoproject.com/en/1.4/topics/http/urls/). |
| 129 | + |
| 130 | +### Codespeed settings |
| 131 | +The main config file is `settings.py`. There you configure everything related |
| 132 | +to your set up. |
0 commit comments