
Ask HN: How do you deploy a Django app in 2020? - eptakilo
Hi. I&#x27;m a mid-level software engineer trying to deploy a small (2000 max users) django app to production.<p>If I Google: How to deploy a Django app. I get 10+ different answers.<p>Can anyone on HN help me please.
======
rasulkireev
I strongly recommend DigitalOcean.

They have a fantastic tutorial on deploying a Django app ->
[https://www.digitalocean.com/community/tutorials/how-to-
set-...](https://www.digitalocean.com/community/tutorials/how-to-set-up-
django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04)

If you end up using DigitalOcean here is my referral link that will give you
$100 of hosting for free (20 months of free droplet use) ->
[https://m.do.co/c/a2a2c0826ff3](https://m.do.co/c/a2a2c0826ff3)

------
tothrowaway
You'll probably get 10 different answers here too.

I use uwsgi in emperor mode. I have a Makefile that runs a few SSH commands on
production to clone my git repo at a specific commit, builds a virtual
environment from requirements.txt, and atomically swaps a symlink to a uwsgi
socket. Nginx in front of it all. It's pretty much the Python equivalent of
FTPing HTML files to a web server.

Uwsgi is terrifying because it has so many options (and I wonder how secure it
is), but it has never failed me. Packaging and containerizing things sounds
cool, but I just can't justify spending time on it when my setup works fine
(I'm a solo dev).

~~~
westurner
If you have only one production server, dokku is "A docker-powered PaaS that
helps you build and manage the lifecycle of applications." Dokku supports
Heroku buildpack deployment (buildstep), Procfiles, Dockerfile deployment,
Docker image deployment, git deployment (gitreceive), or tarfile deployments.
[https://github.com/dokku/dokku](https://github.com/dokku/dokku)

There are a number of plugins for Dokku. Dokku ships with the nginx plugin as
the HTTP frontend proxy. Dokku supports SSL certs with the certs plugin.

When you need to move to more than one server, what do you do? There's now a
dokku-scheduler-kubernetes plugin which can do HA (high availability) which is
worth reading about before you develop _and document_ your own deployment
workflow. [https://github.com/dokku/dokku-scheduler-
kubernetes](https://github.com/dokku/dokku-scheduler-kubernetes)

I also always put build, test, and deployment commands in a Makefile.

------
westurner
Package it; as a container or as containers that install a
RPM/DEB/APK/Condapkg/Pythonpkg (possibly containing a zipapp). Zipapps are
fast.

If you have any non-python dependencies, a Pythonpkg only solves for part of
the packaging needs.

Producing a packaged artifact should be easy and part of your CI build script.

Here's the cookiecutter-django production docker-compose.yml with containers
for django, celery, postgres, redis, and traefik as a load balancer:
[https://github.com/pydanny/cookiecutter-
django/blob/master/%...](https://github.com/pydanny/cookiecutter-
django/blob/master/%7B%7Bcookiecutter.project_slug%7D%7D/production.yml)

Cookiecutter-django also includes a Procfile.

With k8s, you have an ingress (~load balancer + SSL termination proxy) other
than traefik.

You can generate k8s YML from docker-compose.yml with Kompose.

I just found this which describes using GitLab CI with Helm:
[https://davidmburke.com/2020/01/24/deploy-django-with-
helm-t...](https://davidmburke.com/2020/01/24/deploy-django-with-helm-to-
kubernetes/amp/)

What is the command to scale up or down? Do you need a geodistributed setup
(on multiple providers' clouds)? Who has those credentials and experience?

How do you do red/green or rolling deployments?

Can you run tests in a copy of production?

Can you deploy when the tests that run on git commit pass?

What runs the database migrations in production; while users are using the
site?

If something deletes the whole production setup or the bus factor is 1, how
long does it take to redeploy from zero; and how much manual work does it
take?

CI + Ansible + Terraform + Kubernetes.

Whatever tools you settle on, django-eviron for a _12 Factor App_ may be
advisable. [https://github.com/joke2k/django-
environ](https://github.com/joke2k/django-environ)

The Twelve-Factor App: [https://12factor.net/](https://12factor.net/)

