Cookiecutter Django Dokku
A template for jumpstarting Django projects and deploying with Dokku.
Instead of using django-admin startproject to start a new Django application from scratch, you can use this cookiecutter project to start with a Dockerized application ready for Dokku deployment. Some additional common Django features like an extended User model with Email as identification token field, setting up restframework, etc can also be initialized during the initial project set up.
Dokku is a mini-Heroku, powered by Docker. It simplifies the process of building and managing the lifestyle of applications. Once Dokku is set up in a host, you can push codes via Git, just like Heroku.
Instructions below specify how to start your project from this cookiecutter template and also a guideline on how to set up Dokku on your server.
Set Up A Project
cd myproject docker-compose up --build
Whitenoise for static file serving in Production
Gunicorn, Python WSGI HTTP Server used in Production
These can be setup during the initial project integration
- Django by default ships with username as the identification token field. (ie. login with username) Select 'y' to email _user for using email instead.
- Select 'y' to use_celery for Celery with a Redis backend for Distributed Tasks.
- To configure sentry you have to add the SENTRY_DSN_URL and initialize it with your own DSN URL that sentry provides for your project.
dokku config:set myproject SENTRY_DSN_URL=MYSENTRYDSNURL
- Django REST framework is a powerful and flexible toolkit for building Web APIs. Select 'y' to use_rest_framework prompt for this library.
By selecting 'y' to "use_auth_endpoints":
- if you're not using restframework, you can get allauth's accounts views.
- if you chose to use_rest_framework, you get rest-auth's API endpoints. These APIs ship with a few basic test cases written with pytest.
- Again, if you're using Restframework, you can plug in the Restframework Docs as well.
Setting up Dokku on a Linux Server
# install the latest stable version of dokku wget https://raw.githubusercontent.com/dokku/dokku/v0.12.10/bootstrap.sh; sudo DOKKU_TAG=v0.12.10 bash bootstrap.sh # Once the installation is complete, you can open a browser to setup your SSH key and virtualhost settings. # Open your browser and navigate to the host's IP address - or the domain you assigned to that IP previously # Configure Dokku via the web admin. # create the app dokku apps:create myproject # Set environtment variable for ALLOWED_HOSTS. # YOUR_HOST is the host's IP address - or the domain you assigned to that IP dokku config:set ALLOWED_HOSTS=YOUR_HOST # install the postgres plugin sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git # create a postgres service dokku postgres:create myproject-database # link postgres service to the app dokku postgres:link myproject-database myproject # if your're using Celery, you need to setup Redis # install the redis plugin sudo dokku plugin:install https://github.com/dokku/dokku-redis.git redis # create a redis service dokku redis:create myproject-redis # link postgres service to the app dokku redis:link myproject-redis myproject
Deploying the app from your local machine
# add remote dokku url git remote add dokku email@example.com:myproject # push your apllication git push dokku master
- Cookiecutter Django
- Dokku Installation
- Dokku Redis
- Dokku Application Deployment