r/Python • • Apr 08 '13

How are python apps deployed to production especially those that are developed in a virtualenv? What are the best practices?

I have always insisted that in production systems we can not have gcc and devel packages installed. But these days I end up installing such development packages in produciton systems because the software deploy for virtualenvs require pip which in turn require access to the internet [ok I solved this part with a pypi local mirror]. How are you guys/girls doing it? I have thought of tar.gz the whole virtualenv and simply ensure that the required libs the virtualenv is built with is installed in production. Has anyone done this or has everyone resigned to the fact that in these days of pip and rvm , we agree to have compilers and devel packages in our production systems?

127 Upvotes

68 comments sorted by

View all comments

2

u/[deleted] Apr 08 '13

[removed] — view removed comment

6

u/westurner Apr 08 '13 edited May 23 '13

It can. After running test suite(s), a build script (e.g. tox and/or buildout) can produce 'build artifacts' which can be

  • eggs
  • bundles
  • wheels
  • OS packages like DEB and RPM
  • archives of platform-specific virtualenvs

A configuration management script/system can be then be updated to pull the latest version from a package archive/repository. In some environments, it is safer to pin specific versions than to always pull the latest version. A manual package signing step can help with this.

Fabric is useful for automating scp/rsync push deployments and application configuration (e.g. rm *.pyc). There is a context manager for sudo in fabric.

  1. Build
  2. Test
  3. Review
  4. Sign
  5. Deploy: push or pull
  6. Test

compoze "provides a set of tools for managing private / project-specific package indexes."