An expanded version of my PyCon US 2013 talk held at EuroPython 2013 in Florence.
River Bar, 2013Solid PythonApplicationDeployments ForEverybodyHynek Schlawack
View Slide
@hynekhttp://hynek.mehttp://github.com/hynekhttp://www.variomedia.deH!
?
AHEAD
http://ox.cx/dTe Oe & Ol Ln
OPINIONSAHEAD
PaaSSchema Migrations
KyCnet
easy≠simple
“Simplicity isprerequisitefor reliability.”— Edsger W. Dijkstra
“It is important tofind simple solutionsinstead of stoppingas soon as a firstsolution is found.”— Donald Knuth
Put effort intomaking yourdeploymentssimple.
Dvlpet
No!
“Python 2.4 is notsupported. It came out8 years ago. That's olderthan Youtube. Upgrade.”— Kenneth Reitz
Sal PafrKey Infrastructure!
Sal PafrApplication is tied to server OS version.Upgrading servers == updating your app.Some servers upgraded?
Bt Hynek…My boss won’tlet me!
tests!Dvlpet
אל
spottyoutdatedloss of controlSse Pcae
Ue vruln$ virtualenv venv; . venv/bin/activate$ pip install pyramid requests pytest$ py.test…$ pip freeze >requirements.txt…$ pip install -r requirements.txt
Pn Dp Hr“Django == 1.4.3”Don’t rely on SemVer!update w/ pip-tools
SECURITY!Bt Hynek…
Scrt!?It’s your Job.
Si I
+ git
+ gitNe!
Fabric
build toolsrepetitivedownloadsWa’s Wog!?
.rpm.deb.pkg.tgz
introspectionCM integrationversatileNtv Pcae !?
1. check out from VCS2. create virtualenv3. install dependencies4. do whatever you want5. package result6. push to your repo
Abuse the Pipelinerun testsLESS/SASS/CoffeeScriptcompressioncache busting
Packaging is hard!Bt Hynek…
fpmNp.
fpm \-s dir \-t deb \
repo serverBt Hynek…
Rp Sredpkg -itar.bz2
Atmt!e
app_name: whoisproject: DOMbuild_deps:- libpq-devrun_deps:- libpq5- authbind
Tee’s mr taoe wy t d i…
!ل
Cn grtoMngmndeclarativedescribe the goalCM choses the path
Sltosprise-oriented features toto compare the twopet OpenourcePuppetEnterprise✔✔ ✔
prise-oriented features toto compare the twopet OpenourcePuppetEnterprise✔✔ ✔Not easy at all.Sltos
Wy aya?safety/securityreproducible“later”
safety/securityreproducible“later”Wy aya?
Ts I i Saig
r t
r tNein!
Js dn’t.
Piiee Prdrop privilegesauthbind
Need dat POWER!Bt Hynek…
Snl ProeWresceleryrqzerorpcperspective broker/AMP
B Prni/bin/falseiptablesfilesocketsREVOKEALLSSLfail2ban
/bin/falseiptablesfilesocketsREVOKEALLSSLfail2banB Prni
$ ./manage.py runserver ▌[0] 0:bash*
$ ./manage.py runserver ▌[0] 0:bash*ᔒ༗!
I’s Es!upstartsystemdsupervisordcircus…
Eape: usat$ cat /etc/init/yourapp.confstart on static-network-upstop on deconfiguring-networkingrespawnchdir /path/to/yourappsetuid yourappexec /path/to/gunicorn_django settings.py$ start yourapp
Lglog to stderrredirect stderr sysloguse OS tools
Lg…[uwsgi]log-syslog = your-app…twistd --syslog --prefix your-app …
Lgif $programname == 'you-app' \then /var/log/your-app.log& ~
+ mod_wsgi
+ mod_wsgiНет!
DslieUsing Apache isperfectly fine.
Iff you decideconsciouslyfor it.Dslie
mod_wsgi
mod_wsgi ??
+gor
+gorBetter separationof concerns.
Es t St U: gncr$ gunicorn_django settings.py$ gunicorn_paster settings.ini
$ cat settings.py…INSTALLED_APPS = (…"gunicorn",)…$ manage.py run_gunicornEs t St U: gncr
location / {proxy_pass unix:///tmp/app.sock;}location /static/ {root /your/app/public/;}Es t St U: nix
Fo Es tAEOE
Text
Sil Es: usiuwsgi --emperor production.ini…[uwsgi]paste = config:%puwsgi-socket = /tmp/app.sockprocesses = 2…
location / {include uwsgi_params;uwsgi_param UWSGI_SCHEME $scheme;uwsgi_pass unix:///tmp/app.sock;}Sil Es To: nix
Dpo!
Rlbc!
Mntr
Mauestatsdgraphiteyunomi
gt 1
http://ox.cx/d@hynek http://hynek.mehttp://vrmd.de