Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Deployability of Python Web Applications
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Bruno Renié
July 02, 2013
Programming
2.4k
17
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Deployability of Python Web Applications
Bruno Renié
July 02, 2013
More Decks by Bruno Renié
See All by Bruno Renié
Visibility for web developers
brutasse
3
480
Decentralization & real-time with PubSubHubbub
brutasse
1
190
Stop writing settings files
brutasse
21
2.6k
Class-based Views: patterns and anti-patterns
brutasse
9
1.7k
Packager son projet Django
brutasse
4
590
Staticfiles : tout ce qu'il faut savoir, rien que ce qu'il faut savoir
brutasse
4
590
Introduction to Django
brutasse
3
460
Other Decks in Programming
See All in Programming
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
230
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
7.2k
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
1
540
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
150
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
1
160
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
820
act1-costs.pdf
sumedhbala
0
150
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
160
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
120
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
340
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.6k
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
Featured
See All Featured
Six Lessons from altMBA
skipperchong
29
4.3k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
180
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
180
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
KATA
mclloyd
PRO
35
15k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Code Reviewing Like a Champion
maltzj
528
40k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Transcript
Bruno Renié — EuroPython 2013 Deployability of Python web applications
Deployability, n The extent to which something is deployable
Disclaimer Most of this isn't python-specific or even web-specific Oriented
at custom infrastructures Some things still apply if you're on PaaS
How easy it is to install, configure and operate your
software?
Mostly about devs and ops working together
12factor.net
installation configuration operation
Installation
Installing postgres sudo apt-get install postgresql
Installing a python webapp sudo apt-get install build-essential python-virtualenv git
clone https://
[email protected]
/corp/repo cd repo virtualenv env env/bin/pip install -r requirements.txt # Figure out PYTHONPATH
Installing a python webapp sudo apt-get install build-essential python-virtualenv git
clone https://
[email protected]
/corp/repo cd repo virtualenv env env/bin/pip install -r requirements.txt # Figure out PYTHONPATH
Installing software is a solved problem Just use packaging Yep,
python packaging
Why python packaging? Release process Dependency management Trivial rollbacks Easy
system packaging
Packaging in 30 seconds # setup.py from distutils.core import setup
from setuptools import find_packages with open('requirements.txt') as reqs: install_requires = reqs.read().split('\n') setup( name='project', version=__import__('project').__version__, packages=find_packages(), include_package_data=True, zip_safe=False, install_requires=install_requires, ) # MANIFEST.in include requirements.txt recursive-include project *
Private package hosting Local filesystem Network-based, ala pypi.python.org python setup.py
sdist pip install --download dist -r requirements.txt rsync -avz -e ssh dist/ host.corp.com:/srv/pypi pip install --no-index --find-links=/srv/pypi myproject HTML directory index (apache / nginx / SimpleHTTPServer) pip install --no-index --find-links=http://host myproject
System packages fpm -s python -t deb setup.py awk -F=
'{printf "fpm -s python -t deb -v %s %s\n", $3, $1}' \ requirements.txt | sh https://github.com/rcrowley/freight https://github.com/jordansissel/fpm Sign, upload to your private repository sudo apt-get install python-myproject sudo apt-get install python-myproject=1.2.3
Pin your dependencies Bad Good Django Django>=1.4,<1.5 Django==1.4.5 http://nvie.com/posts/pin-your-packages/ This
is for end products, not libraries
Configuration
Configuring postgres $EDITOR /etc/postgresql/9.2/main/postgresql.conf service postgresql restart
Does your app have a config file? settings.py, production_settings.py are
not config files Configuration != code
Problems with configuration as code Incompatible with packaging Environment-specific code
Production-specific code will break production. Code shouldn't be tied to environments Code shouldn't be generated (salt / puppet / fabric)
Define your configuration What changes between environments? Database Secret key
Host / port Credentials to external services (AWS, Sentry…) Read configuration from your code .ini files yaml environment variables …
Code changes ↓ release, deploy app Infrastructure changes ↓ write
config, reload app
Config as environment variables Trivial to set with $PROCESS_MANAGER Native
to every programming language De-facto standard (PaaS). Interoperability! Shared hosting Apache Pros Cons
Case study: Django settings Before After DATABASES = {'default': {'HOST':
'localhost', …}} settings_local.py DATABASES = {'default': {'HOST': 'prod', …}} settings_prod.py DATABASES = {'default': {'HOST': 'staging', …}} settings_staging.py DATABASES = {'default': dj_database_url.config()} settings.py DATABASE_URL="postgres://host:5432/db" env
Config patterns SECRET_KEY = os.environ['SECRET_KEY'] KeyError: 'SECRET_KEY' PORT = int(os.environ.get('PORT',
8000)) Sane defaults when possible Prevent the app from booting if something critical is missing Use *_URL and parsers to reduce the number of variables EMAIL_URL DATABASE_URL REDIS_URL
In development django-dotenv virtualenvwrapper postactivate hooks custom manage.py envdir …
Operation
WSGI Have a WSGI entry point gunicorn myapp.wsgi -b 0.0.0.0:$PORT
Stateless processes Persistence via external services Database Caching Storage …
Scale out with processes More traffic? Spawn more processes. Caveat:
backend services rarely scale horizontally
Maximize dev/prod parity Same software Same people Same versions If
you use postgres in production, use postgres in development PostgreSQL 9.1 and 9.2 do not perform equally Developers should know about infrastructure
Continuous integration/deployment CI != green badge on your github page
CD != always running master in production Having shippable code Deploying it whenever your want CI CD tested packaged installable
Example workflow Commit Run tests Package Staging Production
Example workflow Staging Production Run tests Commit Package manual or
automated Jenkins, SaltStack, IRC bots are your automation friends
use packaging to manage software clearly define the configuration contract
automate as much as possible to minimize deployment friction
@brutasse
[email protected]
?