RoPython Cluj Meetup - 26 Feb. 2019
Dokku and Digital OceanDeploying your Python apps using
How to deploy your very own PaaS on a Digital Ocean droplet using Dokku (https://github.com/dokku/dokku/) a Docker powered "poor mans" mini Heroku bash script. +Demo: setup a simple Python app and deploy it using git (and if we have time automate this using Gitlab CI/CD).
Create a new droplet using the
One-click appsoption and choosing
Dokku 0.xx.xx on 18.04. This shortcut should autocomplete most of the options you need. (NOTE: while the smallest 1GB instance should be enough to get you started, I recommend going with the at least a 2GB droplet later on).
ADNS record to point a (sub)domain to your new droplet IP address (ex.
Access the domain in a browser and you should be presented with the initial Dokku instance setup (as seen in this image). Press
Finish setupafter making changes.
Connect to the Dokku instance to do some additional updates:
# On the Dokku host # Update the dokku repo keys as they are outdated on the one-click apps $ wget -qO - https://packagecloud.io/dokku/dokku/gpgkey | sudo apt-key add - $ sudo apt-get update $ sudo apt-get upgrade # Do additional setup you might need (ex.: apt-get install fail2ban)
- Install PostgreSQL and Let's Encrypt Dokku plugins (full plugin list here: http://dokku.viewdocs.io/dokku/community/plugins/):
# On the Dokku host $ sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git $ sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git $ dokku plugin
- Create a
helloworldDokku app where we will deploy our project and a database for the app to use:
# On the Dokku host $ dokku apps:create helloworld # Creating the database container $ dokku postgres:create helloworld-db # Link the database to the app $ dokku postgres:link helloworld-db helloworld # Check the postgres plugin set the app environment config values for the database connection $ dokku config helloworld # Check that the app subdomain vhost was created and assigned to the app $ dokku domains:report
- On you local machine create a project directory and install Django in a virtual env using
# On your local machine # This will create a new Django project based on a Heroku open-source template $ django-admin startproject --template=https://github.com/heroku/heroku-django-template/archive/master.zip --name=Procfile helloworld $ git init $ git add -A $ git commit -m "Initial commit"
- In order to deploy the above project we have to add the Dokku host as a git remote:
# On your local machine # The user must be `dokku` otherwise it won't work. Also, the string after `:` must be the name of the Dokku app created earlier $ git remote add dokku email@example.com:helloworld # Deploy the app $ git push dokku master # We should be able to access the project at http://ropython.example.com/ at this point
- As a final step, we can get the project to be served over HTTPS using a Let's Encrypt certificate:
# On the Dokku host $ dokku letsencrypt helloworld # We should be able to access the project at https://ropython.example.com/ at this point