RoPython Cluj Meetup - 26 Feb. 2019
Dokku and Digital Ocean
Deploying your Python apps usingPresentation description:
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 apps
option and choosingDokku 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). -
Add the
A
DNS record to point a (sub)domain to your new droplet IP address (ex.ropython.example.com
). -
Access the domain in a browser and you should be presented with the initial Dokku instance setup (as seen in this image). Press
Finish setup
after 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
helloworld
Dokku 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
pip
orpipenv
, then:
# 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 dokku@ropython.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
- Profit!