python - How to Add Docker to Django + Gunicorn + Nginx + Fabric -


i using django gunicorn daemon , nginx proxy , static files. have simple fabric script "automate" actions:

  1. we work on virtualenv on our local computers
  2. we push application our github repo
  3. we ssh server, , run fabric script in github repo
  4. it pulls github, merges if required, restarts nginx , gunicorn

there problem this, example first deploy, need clone github manually.

now, in stage our application sent out our clients can host own servers (and might need scale in near future). require docker containers deploy on own servers. have ssh connection servers update deployment of our application.

however, having hard time figure out might optimal way automate this, i.e. sequence of actions need take every time have new release using fabric.

my recommendation create dockerfile , on each commit release branch have sort of continuous integration server (jenkins, circleci, etc) pull code, run set of tests, build , release new docker image. might want private if require payment - that's easy enough do, can set private docker registry. might find better workflow current internal one, given it's automated.

here example of dockerfile might like:

from debian:stable add . /code workdir /code run apt-get update && apt-get install -y python-dev run pip install -r requirements.txt cmd python run.py 

this example, have no idea how code structured, assumes dockerfile peered script, run.py, knows how things running. assumes want use debian:stable - there lots of options there , need choose works best you. assumes have dependencies organized in requirements.txt file. finally, threw apt-get in there show how can run arbitrary commands , might install python's dev stuff.

depending on how complicated fabric script is, dockerfile replace it, or can run fabric script step in dockerfile.

you can find more information dockerfile format here: https://docs.docker.com/engine/reference/builder/

edit: should add - there little bit of decision making you'll need make regarding how support having nginx in mix, because typical docker way have second image , container - that's easy enough (and in opinion better architecture having in 1 machine seems be) require attention.


Comments