- Commit and push to GitHub.
- Ansible connects to our servers, pulls latest master from GitHub.
- Ansible touches the app’s uwsgi.ini file to trigger UWSGI to reload.
We are using Supervisor inside the Docker container to start the processes run by the container. Our supervisord.conf looks like the following:
[supervisord]
nodaemon=true
[program:uwsgi]
command = /usr/local/bin/uwsgi --touch-reload=/path/to/code/in/container/uwsgi.ini --ini /path/to/code/in/container/uwsgi.ini
We run a playbook that contains these tasks and takes only a few seconds to run:
- set_fact: host_volume="/path/to/code/on/host"
- name: Git pull the latest code
git: repo=git@github.com:{{ org }}/{{ container }}.git
dest={{ host_volume }}
accept_hostkey=yes
force=yes
- name: Gracefully reload uwsgi
file: path={{ touch_file }} state=touch
If we need to restart the entire container or update system packages, we can do a container deploy, which takes a few minutes, with these tasks:
- name: Add app dir if it doesn't yet exist
file: path={{ host_volume }} owner=nobody group=docker recurse=yes state=directory
sudo: yes
- name: Pull Docker image
command: "{{ item }}"
ignore_errors: yes
with_items:
- docker pull {{ org }}/{{ container }}
- docker stop {{ container }}
- docker rm {{ container }}
- name: Run Docker image with app volumes
command: docker run -d -P -v {{ host_volume }}:{{ container_volume }} --name={{ container }} {{ extra_params }} {{ org }}/{{ container }}