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
Containerless Django
Search
Peter Baumgartner
October 16, 2018
Programming
5
1.7k
Containerless Django
Deploying Django without Docker
Peter Baumgartner
October 16, 2018
Tweet
Share
More Decks by Peter Baumgartner
See All by Peter Baumgartner
Just Enough Ops for Developers
ipmb
0
240
Prepping Your Project for Production
ipmb
2
870
Django Deployments Done Right
ipmb
6
1.5k
High Performance Django: From runserver to Reddit hugs
ipmb
1
1.4k
Getting Started with Salt (PyCon 2014)
ipmb
6
1.3k
Monitoring Infrastructure with SaltStack
ipmb
16
10k
Getting Started with Salt
ipmb
11
1.7k
Other Decks in Programming
See All in Programming
REST API設計の実践 – ベストプラクティスとその落とし穴
kentaroutakeda
2
320
マテリアルって何者?RealityKitで扱うマテリアル入門
nao_randd
0
140
『Python → TypeScript』オンボーディング奮闘記
takumi_tatsuno
1
140
がんばりすぎないコーディングルール運用術
tsukakei
1
190
TVer iOSチームの共通認識の作り方 - Findy Job LT iOSアプリ開発の裏側 開発組織が向き合う課題とこれから
techtver
PRO
0
720
Building an Application with TDD, DDD and Hexagonal Architecture - Isn't it a bit too much?
mufrid
0
370
primeNumberでのRBS導入の現在 && RBS::Traceでinline RBSを拡充してみた
mnmandahalf
0
260
コンポーネントライブラリで実現する、アクセシビリティの正しい実装パターン
schktjm
1
670
Efficiency and Rock 'n’ Roll (Really!)
hollycummins
0
600
イベントソーシングとAIの親和性ー物語とLLMに理解できるデータ
tomohisa
1
160
OpenNext + Hono on Cloudflare でイマドキWeb開発スタックを実現する
rokuosan
0
110
Devinで実践する!AIエージェントと協働する開発組織の作り方
masahiro_nishimi
6
2.6k
Featured
See All Featured
Building Applications with DynamoDB
mza
95
6.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
Designing Experiences People Love
moore
142
24k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Speed Design
sergeychernyshev
30
970
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
850
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
Documentation Writing (for coders)
carmenintech
71
4.8k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
The Cult of Friendly URLs
andyhume
78
6.4k
Transcript
DjangoCon US—San Diego Oct 2018 Deploying without Docker Containerless Django
Peter Baumgartner
Founder at Lincoln Loop—lincolnloop.com Former SysAdmin, DevOps for 8 years
Author of High Performance Django About Me
Docker is cool!
@ipmb | #djangocon Docker is cool! The “pipeline” Security Isolation
Dev/prod parity
Just bundle the entire OS
Some philosophy
“ —Mike Perham https://www.mikeperham.com/2016/02/09/kill-your-dependencies/ No code runs faster than no
code. No code has fewer bugs than no code. No code uses less memory than no code. No code is easier to understand than no code. “
None
@ipmb | #djangocon Docker Drawbacks Slow Extra abstractions More software,
more problems
None
How did we get here?
@ipmb | #djangocon Deployments sucked Dependencies would shift underneath you
Build tools and dev packages needed to be installed Multiple languages, multiple builds (Python & Node)
@ipmb | #djangocon The ideal deployment Download a binary Create
a configuration file Run it
@ipmb | #djangocon The ideal deployment /usr/local/bin/traefik \ --configFile=/etc/traefik/traefik.toml /usr/local/bin/telegraf
\ --config=/etc/telegraf/telegraf.conf /usr/sbin/nginx -c /etc/nginx/nginx.conf
@ipmb | #djangocon Python isn’t C or Go Requires a
VM Dynamic linking Packaging isn’t straightforward
None
Can we do better?
@ipmb | #djangocon We already are! Lock files via pipenv
or poetry Pre-compiled wheels (Pillow, psycopg2-binary, etc.) Still lots of holes - Assembling virtualenvs - Static files - Production webserver
@ipmb | #djangocon Prior art Private PyPI virtualenv-clone Platter dh-virtualenv
Pex
@ipmb | #djangocon ZIP applications? Part of Python since 2.6
PEP-441 improves support in 3.5 Create a ZIP archive of your project. Run it with Python. …but no mechanism for handling dependencies
None
@ipmb | #djangocon Enter shiv! A project from LinkedIn Zipapps
with dependencies A single artifact you can build → test → deploy ./myproject.pyz runserver
Django as a zipapp
Package your project with setup.py
@ipmb | #djangocon Include templates & static files Create a
MANIFEST.in graft your_project/collected_static graft your_project/templates
@ipmb | #djangocon Production webserver gunicorn + whitenoise ⭐ https://pypi.org/project/django-pyuwsgi/
@ipmb | #djangocon Build your zipapp
@ipmb | #djangocon Run your zipapp ./yourproject.pyz pyuwsgi --http=:8000
@ipmb | #djangocon Configuration Same zipapp, but different settings per
environment Options: - Multiple settings files and DJANGO_SETTINGS_MODULE - Environment variables - ⭐ https://pypi.org/project/goodconf/
@ipmb | #djangocon The zipapp pipeline Use CI (Travis, CircleCI,
Bitbucket, etc.) to: - Build - Test - Push Deploy = Download and run
None
What about security?
Systemd's got your back
@ipmb | #djangocon Systemd is awesome ProtectSystem=strict ProtectHome=true DynamicUser=true CapabilityBoundingSet=~CAP_SYS_ADMIN
AppArmorProfile=srv.yourproject.pyz ProtectKernelTunables=true ProtectControlGroups=true ProtectKernelModules=true PrivateDevices=true PrivateTmp=true SystemCallArchitectures=native
What about isolation?
@ipmb | #djangocon Isolation You still need Python installed globally
Easy to install multiple Pythons on one server Docker has better isolation, but do you need it?
@ipmb | #djangocon What about parity? Zipapp is the same
from CI to all deployed environments Use Docker to mimic deployment envionrment locally (or don't)
@ipmb | #djangocon Pros Simpler. No Docker on the server.
No registry. ~1M fewer lines of code to depend on. Smaller artifacts Faster deployments It's just Python
@ipmb | #djangocon Cons Not as isolated as true containers
Requires Python runtime on the server Python-specific Not cross-platform compatible (if you have packages with C extensions)
@ipmb | #djangocon Sweet spot for zipapps You are deploying
primarily Python services You have outgrown PaaS (Heroku, PythonAnywhere, Divio, etc.) You have fewer than 50 services to maintain
None
None
Thanks! Peter Baumgartner pete@lincolnloop.com @ipmb