Updating Django Source with Docker Deployments

While deploying docker multiple times, you may not want to copy over your Django source code every time you do a deployment.

Setting up supervisord

Luckily there is an easy way to manage this. Since you are working with Django, there is a good chance that you are also managing the processes (like uwsgi) with supervisord.

Here are some of the steps that you can take with supervisord

Here’s a sample code:

    [program:source-updater]
    redirect_stderr = true
    stdout_logfile = /shared/source_code_updater.log
    directory = /ws/
    command = /ws/source_code_updater.sh
    autorestart=False

Updating the source code

Few things are important to note in a docker deployment:

With that idea, do a checkout and update the source code according to specific tag:

    git checkout -f tags/your_tag_name
    git pull origin tags/your_tag_name

Telling uwsgi about the updated source code

Once you have updated your source code, you need to re-load the project onto uwsgi so that nginx or apache can pick it up. The simplest way to achieve it using the config parameter of uwsgi: --touch-reload. It will reload uWSGI if the specified file is modified/touched

Just remember to setup supervisord in your Dockerfile with this config parameter.

[program:app-uwsgi]
redirect_stderr = true
stdout_logfile = /var/shared/_uwsgi.log
command = /ws/ve_envs/rwv2/bin/uwsgi --touch-reload=/ws/wsgi.ini --ini /ws/wsgi.ini

You can choose any file. I choose uwsgi.ini because the contents never really need to change in it.

comments powered by Disqus