Skip to content

Instantly share code, notes, and snippets.

@fizerkhan
Created April 30, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fizerkhan/7716e1957b08b9395dc5 to your computer and use it in GitHub Desktop.
Save fizerkhan/7716e1957b08b9395dc5 to your computer and use it in GitHub Desktop.
Fast code deployments with Docker in Digital ocean
  1. Commit and push to GitHub.
  2. Ansible connects to our servers, pulls latest master from GitHub.
  3. Ansible touches the app’s uwsgi.ini file to trigger UWSGI to reload.

Supervisor configuration:

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

For a quick code deploy,

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

For a full deploy

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 }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment