Cookiecutter-django: Docker Zero Downtime deployments

Created on 21 Apr 2017  路  7Comments  路  Source: pydanny/cookiecutter-django

This will complicate things a little, but is a nice to have.

Thoughts?

docker

Most helpful comment

You create a database migration first thats both compatible with the new and the old code and deploy it. Once that鈥榮 complete, you deploy code changes to use the migrated scheme and finally you add a second migration that removes the old one.

All 7 comments

Do it!

@jayfk, how is this going? Can I be of any help?

I'd love to see this too.

Djangopackages has it:
https://github.com/djangopackages/djangopackages/blob/master/docker-compose.yml#L9-L35
https://github.com/djangopackages/djangopackages/blob/master/fabfile.py
https://github.com/djangopackages/djangopackages/blob/master/compose/caddy/Caddyfile#L6-L15

The main idea is to have two running Django containers that are load balanced by the webserver.

  • Code pushed
  • First container is being rebuild and goes down
  • Load balancer chooses second container to serve requests
  • First container starts up
  • Load balancer spreads requests evenly between new and old code
  • Second container is being rebuild and goes down
  • Load balancer picks the first container, is now serving only new code
  • Second container starts up
  • Load balancer picks up both containers and is now serving both old and new code

If someone wants to work on this, I'd be happy to review it.

Wondering what should we do if there's a new db migration in code pushed?

You create a database migration first thats both compatible with the new and the old code and deploy it. Once that鈥榮 complete, you deploy code changes to use the migrated scheme and finally you add a second migration that removes the old one.

@browniebroke @jayfk @pydanny I'm not too acquainted with Traefik, but since we've moved on from caddy, here's something that could be useful if we keep trying Blue/Green deployment: https://www.katacoda.com/courses/distributed-microservices/3-blue-green-routing

Blue/Green deployment would work for non-async views (so no Channels or Django 3 web sockets, unless I read that README.md wrong) unless that load balancing configuration works by slowly moving traffic instead of immediate. Then again, I have no idea how it works and was wondering if this PR could be continued in development by someone who did know? Or should I create a new issue to track this so other GH users can see it more visibly?

Was this page helpful?
0 / 5 - 0 ratings