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
The Python Deployment Albatross - PyTennessee 2017
Search
Cindy Sridharan
February 05, 2017
Technology
1
470
The Python Deployment Albatross - PyTennessee 2017
Second stab at this talk.
Cindy Sridharan
February 05, 2017
Tweet
Share
More Decks by Cindy Sridharan
See All by Cindy Sridharan
Unmasking netpoll.go
copyconstructor
4
2.3k
Monitoring in the time of Cloud Native
copyconstructor
4
370
Prometheus - A Whirlwind Tour
copyconstructor
11
3.5k
Prometheus at Google NYC Tech Talks Nov 2016
copyconstructor
10
2.3k
Other Decks in Technology
See All in Technology
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
280
Jetpack Composeで始めるServer Cache State
ogaclejapan
2
170
Snykで始めるセキュリティ担当者とSREと開発者が楽になる脆弱性対応 / Getting started with Snyk Vulnerability Response
yamaguchitk333
2
180
AWS re:Invent 2024 ふりかえり
kongmingstrap
0
130
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.8k
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
240
大幅アップデートされたRagas v0.2をキャッチアップ
os1ma
2
520
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
250
kargoの魅力について伝える
magisystem0408
0
200
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
160
20241214_WACATE2024冬_テスト設計技法をチョット俯瞰してみよう
kzsuzuki
3
440
Featured
See All Featured
Six Lessons from altMBA
skipperchong
27
3.5k
The Pragmatic Product Professional
lauravandoore
32
6.3k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Designing for humans not robots
tammielis
250
25k
Faster Mobile Websites
deanohume
305
30k
GraphQLとの向き合い方2022年版
quramy
44
13k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
The Cult of Friendly URLs
andyhume
78
6.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Site-Speed That Sticks
csswizardry
2
190
Transcript
The Python Deployment Albatross CINDY SRIDHARAN @COPYCONSTRUCT PYTENNESSEE FEBRUARY 5,
2017 NASHVILLE, TN
setup.py
What’s our goal?
Hermetically sealed, uniform, reproducible Python artifacts
Hermetically sealed
✓ Isolate pure Python dependencies ✓ Isolate compile time native/non-Python
dependencies ✓ Isolate runtime native/non-Python dependencies
uniform
Output of the build process is platform and architecture agnostic
Reproducible
A set of software development practices that create a verifiable
path from human readable source code to the binary code used by computers.
What is Python? python hello_world.py Python – or /usr/bin/python –
as your system understands it, is a program called the interpreter
How does Python know what to import from where? site.py
sys.prefix sys.exec_prefix
None
None
WHEELS VIRTUALENV PEX DOCKER CONDA NIX
wheels
but before wheels there were …
eggs-ecutable
purely a distribution format wheels
no build system needed on target host no C compiler
required wheels
wheels no arbitrary code execution like sdists Ergo faster installation
pip builds and caches wheels by default
ergo less tied to a specific version of Python Creates
.pyc files as a part of the installation wheels
manylinux wheels
None
virtualenv
helps “isolate Python environments”
✓ Isolates per-project pure Python dependencies from one another virtualenv
virtualenv ✓ Isolates per-project pure Python dependencies from system Python
✓ Isolates header files and shared libraries *if these are
packaged* virtualenv
greenlet.h is installed local to the virtualenv
… as is greenlet.so
Where virtualenv falls short Uses system provided headers and .so
files if not packaged
- - relocatable doesn’t always work
dh-virtualenv
PEX
Any directory with an __init__.py is considered a package Python
import quirks
__init__.py
Any directory with a __main__.py is treated as an executable
Python import quirks
__main__.py package is now executable
python –m package will execute package/__main__.py if it exists Python
import quirks
Adding #!/usr/bin/env python to the beginning of any module makes
it an executable Python executables
change permissions of file
Zipfiles A zipfile with an __init__.py is considered a package
Zipfiles A zipfile with a __main__.py is treated as an
executable
zip file is now executable
✓zip files don’t start until a magic zip number ✓
can add arbitrary strings at the start of the file ✓ #!/usr/bin/env python PEX
zip files are also used at Facebook
None
pex file
None
None
None
None
Uses system provided headers and .so files if not packaged
PEX
not cross-platform by default PEX
docker treats packaging as a namespacing problem
What does it mean to containerize a Python process?
Docker image for Python processes
BASE IMAGE DEVELOPMENT HEADERS AND LIBRARIES VIRTUALENV PEX
Best practices for building Docker images for Python ✓ small
images ✓ always use a virtualenv or pex ✓ single process per container
Dockerflow
Challenges of containerization
None
The Docker engine is a container runtime Overlay Networking With
1.12 in Swarm mode, it’s also a cluster scheduler Process manager … and much, much more (service discovery, load balancing, TLS ...) All compiled into one gigantic binary running as root
Logging Metrics Collection Observability Debugging
conda
CONDA or PIP?
PIP lacks a SAT solver
CONDA or WHEELS?
CONDA or VIRTUALENV?
CONDA or DOCKER?
VM ==> DOCKER :: DOCKER ==> CONDA
✓ Python or other modules ✓ System-level libraries ✓ Executable
programs conda package Can be downloaded from remote channels
all build dependencies need to be preinstalled in the build
prefix tarball files generated by the build script to produce a package
None
NIX
referential transparency
An expression is said to be referentially transparent if evaluating
it gives the same value for same arguments. Such functions are called pure functions.
nix expressions Nix expressions specify how to build nix packages,
including, if necessary, their dependencies.
different users have different “views” of the system profiles
profiles
garbage collection any package not in use (no symlinks) by
any generation of any profile
List of all dependencies, recursively, down to the bare minimum
necessary to use that derivation closure
channels a URL that points to a place that contains
a set of Nix expressions and a manifest
A use case for nix
✓ Statically linked Objective-C, C and Lua code ✓ Every
time there’s a MacOS upgrade, hosts need to be reimaged ✓ Application then needs to be recompiled ✓ A nix closure gets around this Why nix closures?
Conclusion ✓ Build wheels ✓ Use a virtualenv (or pex),
even with Docker ✓ Build small Docker images ✓ Explore conda/nix only if needed ✓ Good Luck!
@copyconstruct