|
| 1 | +Blog API |
| 2 | +============================== |
| 3 | + |
| 4 | +A Blog API |
| 5 | + |
| 6 | + |
| 7 | +LICENSE: BSD |
| 8 | + |
| 9 | +Settings |
| 10 | +------------ |
| 11 | + |
| 12 | +Blog API relies extensively on environment settings which **will not work with Apache/mod_wsgi setups**. It has been deployed successfully with both Gunicorn/Nginx and even uWSGI/Nginx. |
| 13 | + |
| 14 | +For configuration purposes, the following table maps the 'Blog API' environment variables to their Django setting: |
| 15 | + |
| 16 | +======================================= =========================== ============================================== =========================================== |
| 17 | +Environment Variable Django Setting Development Default Production Default |
| 18 | +======================================= =========================== ============================================== =========================================== |
| 19 | +DJANGO_AWS_ACCESS_KEY_ID AWS_ACCESS_KEY_ID n/a raises error |
| 20 | +DJANGO_AWS_SECRET_ACCESS_KEY AWS_SECRET_ACCESS_KEY n/a raises error |
| 21 | +DJANGO_AWS_STORAGE_BUCKET_NAME AWS_STORAGE_BUCKET_NAME n/a raises error |
| 22 | +DJANGO_CACHES CACHES locmem memcached |
| 23 | +DJANGO_DATABASES DATABASES See code See code |
| 24 | +DJANGO_DEBUG DEBUG True False |
| 25 | +DJANGO_EMAIL_BACKEND EMAIL_BACKEND django.core.mail.backends.console.EmailBackend django.core.mail.backends.smtp.EmailBackend |
| 26 | +DJANGO_SECRET_KEY SECRET_KEY CHANGEME!!! raises error |
| 27 | +DJANGO_SECURE_BROWSER_XSS_FILTER SECURE_BROWSER_XSS_FILTER n/a True |
| 28 | +DJANGO_SECURE_SSL_REDIRECT SECURE_SSL_REDIRECT n/a True |
| 29 | +DJANGO_SECURE_CONTENT_TYPE_NOSNIFF SECURE_CONTENT_TYPE_NOSNIFF n/a True |
| 30 | +DJANGO_SECURE_FRAME_DENY SECURE_FRAME_DENY n/a True |
| 31 | +DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS HSTS_INCLUDE_SUBDOMAINS n/a True |
| 32 | +DJANGO_SESSION_COOKIE_HTTPONLY SESSION_COOKIE_HTTPONLY n/a True |
| 33 | +DJANGO_SESSION_COOKIE_SECURE SESSION_COOKIE_SECURE n/a False |
| 34 | +======================================= =========================== ============================================== =========================================== |
| 35 | + |
| 36 | +* TODO: Add vendor-added settings in another table |
| 37 | + |
| 38 | +Getting up and running |
| 39 | +---------------------- |
| 40 | + |
| 41 | +The steps below will get you up and running with a local development environment. We assume you have the following installed: |
| 42 | + |
| 43 | +* pip |
| 44 | +* virtualenv |
| 45 | +* PostgreSQL |
| 46 | + |
| 47 | +First make sure to create and activate a virtualenv_, then open a terminal at the project root and install the requirements for local development:: |
| 48 | + |
| 49 | + $ pip install -r requirements/local.txt |
| 50 | + |
| 51 | +.. _virtualenv: http://docs.python-guide.org/en/latest/dev/virtualenvs/ |
| 52 | + |
| 53 | +You can now run the usual Django ``runserver`` command (replace ``yourapp`` with the name of the directory containing the Django project):: |
| 54 | + |
| 55 | + $ python yourapp/manage.py runserver |
| 56 | + |
| 57 | +The base app will run but you'll need to carry out a few steps to make the sign-up and login forms work. These are currently detailed in `issue #39`_. |
| 58 | + |
| 59 | +.. _issue #39: https://github.com/pydanny/cookiecutter-django/issues/39 |
| 60 | + |
| 61 | +**Live reloading and Sass CSS compilation** |
| 62 | + |
| 63 | +If you'd like to take advantage of live reloading and Sass / Compass CSS compilation you can do so with the included Grunt task. |
| 64 | + |
| 65 | +Make sure that nodejs_ is installed. Then in the project root run:: |
| 66 | + |
| 67 | + $ npm install grunt |
| 68 | + |
| 69 | +.. _nodejs: http://nodejs.org/download/ |
| 70 | + |
| 71 | +Now you just need:: |
| 72 | + |
| 73 | + $ grunt serve |
| 74 | + |
| 75 | +The base app will now run as it would with the usual ``manage.py runserver`` but with live reloading and Sass compilation enabled. |
| 76 | + |
| 77 | +To get live reloading to work you'll probably need to install an `appropriate browser extension`_ |
| 78 | + |
| 79 | +.. _appropriate browser extension: http://feedback.livereload.com/knowledgebase/articles/86242-how-do-i-install-and-use-the-browser-extensions- |
| 80 | + |
| 81 | +It's time to write the code!!! |
| 82 | + |
| 83 | + |
| 84 | +Deployment |
| 85 | +------------ |
| 86 | + |
| 87 | +It is possible to deploy to Heroku or to your own server by using Dokku, an open source Heroku clone. |
| 88 | + |
| 89 | +Heroku |
| 90 | +^^^^^^ |
| 91 | + |
| 92 | +Run these commands to deploy the project to Heroku: |
| 93 | + |
| 94 | +.. code-block:: bash |
| 95 | +
|
| 96 | + heroku create --buildpack https://github.com/heroku/heroku-buildpack-python |
| 97 | + heroku addons:add heroku-postgresql:dev |
| 98 | + heroku addons:add pgbackups:auto-month |
| 99 | + heroku addons:add sendgrid:starter |
| 100 | + heroku addons:add memcachier:dev |
| 101 | + heroku pg:promote DATABASE_URL |
| 102 | + heroku config:set DJANGO_CONFIGURATION=Production |
| 103 | + heroku config:set DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE |
| 104 | + heroku config:set DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE |
| 105 | + heroku config:set DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE |
| 106 | + heroku config:set DJANGO_AWS_STORAGE_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME_HERE |
| 107 | + git push heroku master |
| 108 | + heroku run python blog-api/manage.py migrate |
| 109 | + heroku run python blog-api/manage.py createsuperuser |
| 110 | + heroku open |
| 111 | +
|
| 112 | +Dokku |
| 113 | +^^^^^ |
| 114 | + |
| 115 | +You need to make sure you have a server running Dokku with at least 1GB of RAM. Backing services are |
| 116 | +added just like in Heroku however you must ensure you have the relevant Dokku plugins installed. |
| 117 | + |
| 118 | +.. code-block:: bash |
| 119 | +
|
| 120 | + cd /var/lib/dokku/plugins |
| 121 | + git clone https://github.com/rlaneve/dokku-link.git link |
| 122 | + git clone https://github.com/jezdez/dokku-memcached-plugin memcached |
| 123 | + git clone https://github.com/jezdez/dokku-postgres-plugin postgres |
| 124 | + dokku plugins-install |
| 125 | +
|
| 126 | +You can specify the buildpack you wish to use by creating a file name .env containing the following. |
| 127 | + |
| 128 | +.. code-block:: bash |
| 129 | +
|
| 130 | + export BUILDPACK_URL=<repository> |
| 131 | +
|
| 132 | +You can then deploy by running the following commands. |
| 133 | + |
| 134 | +.. code-block:: bash |
| 135 | +
|
| 136 | + git remote add dokku dokku@yourservername.com:blog-api |
| 137 | + git push dokku master |
| 138 | + ssh -t dokku@yourservername.com dokku memcached:create blog-api-memcached |
| 139 | + ssh -t dokku@yourservername.com dokku memcached:link blog-api-memcached blog-api |
| 140 | + ssh -t dokku@yourservername.com dokku postgres:create blog-api-postgres |
| 141 | + ssh -t dokku@yourservername.com dokku postgres:link blog-api-postgres blog-api |
| 142 | + ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_CONFIGURATION=Production |
| 143 | + ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_SECRET_KEY=RANDOM_SECRET_KEY_HERE |
| 144 | + ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_AWS_ACCESS_KEY_ID=YOUR_AWS_ID_HERE |
| 145 | + ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_ACCESS_KEY_HERE |
| 146 | + ssh -t dokku@yourservername.com dokku config:set blog-api DJANGO_AWS_STORAGE_BUCKET_NAME=YOUR_AWS_S3_BUCKET_NAME_HERE |
| 147 | + ssh -t dokku@yourservername.com dokku config:set blog-api SENDGRID_USERNAME=YOUR_SENDGRID_USERNAME |
| 148 | + ssh -t dokku@yourservername.com dokku config:set blog-api SENDGRID_PASSWORD=YOUR_SENDGRID_PASSWORD |
| 149 | + ssh -t dokku@yourservername.com dokku run blog-api python blog-api/manage.py migrate |
| 150 | + ssh -t dokku@yourservername.com dokku run blog-api python blog-api/manage.py createsuperuser |
| 151 | +
|
| 152 | +When deploying via Dokku make sure you backup your database in some fashion as it is NOT done automatically. |
0 commit comments