Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
The Python Deployment Albatross - PyTennessee 2017
Search
Cindy Sridharan
February 05, 2017
Technology
560
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The Python Deployment Albatross - PyTennessee 2017
Second stab at this talk.
Cindy Sridharan
February 05, 2017
More Decks by Cindy Sridharan
See All by Cindy Sridharan
Unmasking netpoll.go
copyconstructor
4
2.6k
Monitoring in the time of Cloud Native
copyconstructor
4
450
Prometheus - A Whirlwind Tour
copyconstructor
11
3.8k
Prometheus at Google NYC Tech Talks Nov 2016
copyconstructor
10
2.6k
Other Decks in Technology
See All in Technology
ゲームのリアルタイム通信から見た QUIC と MoQ
segadevtech
0
110
しろおびから始める!ログ活用の第一歩
shumei_ito
0
920
スキマバイトという雇用形態は存在しないので、雇用期間1日のアルバイト契約を事業者とワーカーが結ぶ手続きを支えるのがタイミーなんです
akitoshiga
0
150
初対面のメンバーがチームを組み、Claude Codeでゼロからサービスをリリース
mkdev10
1
120
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
150
遠藤な_めぐろLT #38 「社内のAI活用推進」@麻布台_20261009
endonanana
0
120
AIカンパニーへの転換を支えた、エンジニアの仕事の再定義
kworkdev
PRO
2
600
夫婦で子育てするための育児標準化
codmoninc
PRO
0
200
AI時代だからこそ推したい!Gitコマンド再入門
munakata
0
180
継続的なAIコスト最適化
bgpat
1
290
AI駆動開発の時代になったのでトヨタ生産方式から見直す
terurou
7
5.9k
FOSS4Gを活用した自治体業務DXの試み
470715
0
150
Featured
See All Featured
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
Design in an AI World
tapps
1
350
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Between Models and Reality
mayunak
4
490
The Curious Case for Waylosing
cassininazir
1
570
Evolving SEO for Evolving Search Engines
ryanjones
0
320
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
320
Music & Morning Musume
bryan
48
7.4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
220
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