| Author | Nnoduka Eruchalu |
| Date | 04/18/2015 |
| Website | http://gravvy.nnoduka.com |
Gravvy just simplified shared memories!
- iOS 7+
- Modern web browsers
- Python
- PostgreSQL
- Amazon Web Services
- REST
- Javascript
- HTML
- CSS
- Bootstrap [Used for responsive mobile interface]
| Module | Description |
|---|---|
settings.py |
Django settings for project |
settings_secret.py |
Secret Django settings for project |
urls.py |
URL dispatcher for project |
utils.py |
Utility functions useful to multiple Django apps |
wsgi.py |
WSGI config for project |
apps/ |
Django apps with backend logic |
apps/account/ |
User account representation and auth. app |
apps/video/ |
Video mashup representation app |
apps/rest/ |
django rest framework customizations |
static/ |
static files for project |
static/css/ |
CSS files |
static/img |
Static images |
static/js/ |
Javascript files |
templates/ |
Django templates used by apps |
templates/404.html |
404 page |
templates/500.html |
500 page |
templates/base.html |
base template used by all templates |
templates/rest_framework |
templates used for customizing browseable REST API |
See requirements.txt
Heroku has published a pretty good set of design notes. This project tries to comply with these as much as possible.
Publicly exposed identifiers (IDs), such as those exposed in RESTful URLs, should not expose (or rely on) underlying technology.
This article here gives a better explanation of what to use as resource identifiers.
Start a virtualenv virtual Python environment. This will create a sandbox
isolated from your existing Python installation so that installed packages
only exist within the sandbox:
virtualenv ENV
Activate the sandbox:
source ENV/bin/activate
Install python libraries:
pip install -r requirements.txt
$ psql -U postgres
$ create role nceruchalu_gravv superuser nocreaterole createdb login PASSWORD '<password>'
Create the database with the following command:
$ createdb -O nceruchalu_gravv -U nceruchalu_gravv nceruchalu_gravv
You can now access the database with the following command:
$ psql nceruchalu_gravv -U nceruchalu_gravv
The Django project is missing the gravvy/settings_secret.py file. A template
version is included for help in setting up the sensitive information needed by
the project.
Run the python manage.py migrate management command to create/update schema
These instructions here are what I did on my Webfaction server.
- Name:
gravvy - App category:
Django - App type:
mod_wsgi 4.4.11/Python 2.7 - The new application will be created in home directory (
~) under~/webapps/gravvy. - Delete the default project folder,
myproject
-
Check if virtualenv is installed on your server:
$ virtualenv --version -bash: virtualenv: command not found -
If Virtualenv is missing, install it on Webfaction with the following:
$ mkdir -p ~/lib/python2.7/ $ easy_install-2.7 pip $ pip install virtualenv -
If you get a permission denied error try this command to install virtualenv inside your user folder:
$ pip install --user virtualenv -
Verify that the installation was successful:
$ virtualenv --version 13.0.1
-
Turn application directory into a virtual Python environment:
$ cd ~/webapps/gravvy $ virtualenv . -
This adds the folders and scripts for a virtual environment inside of the directory which webfaction created for our application.
-
You can now activate the created environment:
$ source bin/activate (gravvy) $
-
Once the initial Virtualenv setup is complete, you can install Django inside it's
lib/python2.7/site-packagesdirectory(gravvy) $ pip install -r requirements.txt -
Modify
httpd.confpaths to use the new python libraries and site-packagesWSGIPythonPath /home/nceruchalu/webapps/gravvy:/home/nceruchalu/webapps/gravvy/gravvy:/home/nceruchalu/webapps/gravvy/lib/python2.7 WSGIDaemonProcess gravvy processes=2 threads=12 python-path=/home/nceruchalu/webapps/gravvy:/home/nceruchalu/webapps/gravvy/gravvy:/home/nceruchalu/webapps/gravvy/lib/python2.7/site-packages:/home/nceruchalu/webapps/gravvy/lib/python2.7
Ref: http://michal.karzynski.pl/blog/2013/09/14/django-in-virtualenv-on-webfactions-apache-with-mod-wsgi/
Add the following lines to ensure all requests to www.gravvy.nnoduka.com are redirected to gravvy.nnoduka.com.
LoadModule alias_module modules/mod_alias.so
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.gravvy\.nnoduka\.com [NC]
RewriteRule ^(.*)$ http://gravvy.nnoduka.com$1 [L,R=301]
Since we are using Apache & mod_wsgi, add this line at the end of the conf file,
after WSGIScriptAlias / ...
WSGIPassAuthorization On
See this post for details.
Access crontab with:
crontab -e
Edit it to perform following functionality:
- Setup PATH, PYTHONPATH to be used by cron's environment
- Restart apache every 30 minutes. This ensures minimal downtime (if at all)
- Backup database daily using configurations hidden in config file [some values redacted]
PATH=/home/nceruchalu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:.
12,32,52 * * * * ~/webapps/gravvy/apache2/bin/start
0 2 * * * pg_dump -U nceruchalu_gravvy -Fc nceruchalu_gravvy > $HOME/db_backups/nceruchalu_gravvy/nceruchalu_gravvy-`date +\%Y\%m\%d`.sql 2>> $HOME/db_backups/cron.log
5 2 * * * pg_dump -U nceruchalu_gravvy nceruchalu_gravvy > $HOME/db_backups/nceruchalu_gravvy/nceruchalu_gravvy.sql 2>> $HOME/db_backups/cron.log
- Create a .pgpass file in
$HOMEwith these contentshostname:port:database:username:password
Follow Apple's documentation on creating .p12 files.
Do not password protect these files and convert them to .pem files by using the following command:
openssl pkcs12 -in aps_production.p12 -out aps_production.pem -nodes -clcerts
python manage.py runserver 0:8000
Generate here: http://www.bennadel.com/coldfusion/privacy-policy-generator.htm
ps -u nceruchalu -o rss,etime,pid,command | awk '{print $0}{sum+=$1} END {print "Total", sum/1024, "MB"}'
-
Generate a
curl-format.txtfile with the following contents:\n time_namelookup: %{time_namelookup}\n time_connect: %{time_connect}\n time_appconnect: %{time_appconnect}\n time_pretransfer: %{time_pretransfer}\n time_redirect: %{time_redirect}\n time_starttransfer: %{time_starttransfer}\n ----------\n time_total: %{time_total}\n \n -
Make a request and view the timings in seconds
curl -w "@curl-format.txt" -s -H "Authorization: Token 57146d9e970c863266fcd89a7b175f66eefe4590" -H "Content-Type: application/json" http://gravvy.nnoduka.com/api/v1/user/videos/ -o /dev/null