SlideShare a Scribd company logo
Packaging a Python
application after you
messed up
Roman Prykhodchenko, Allegro
@romcheg
me@romcheg.me
November 2019, Warsaw
www.devopsdays.pl
DevOpsDays Warsaw 2019
• Maintained and used in house
• Heavily modified django-admin
• Python + HTML + JS
• Open-source + private extensions
• In house: Ubuntu + Docker image
• In community: mostly Ubuntu + deb package but....
DCIM system: Ralph
2
DevOpsDays Warsaw 2019
Problem
• Community builds are often broken
• Troubleshooting takes more time than we have
• No motivation to support the community
3
DevOpsDays Warsaw 2019
Reasons
• Two separate delivery pipelines
• TravisCI: Debian package built and published once a week
• Bamboo: Docker image with private extensions available on demand
• Different artefacts in community and local packages
• Supporting the community is not the team's #1 priority
4
DevOpsDays Warsaw 2019
Solution:
Improve the delivery pipeline by re-thinking packaging.
5
DevOpsDays Warsaw 2019
• ... a file with an .rpm or .deb in the end
• ... a python wheel
• ... a tarball with a source code and a Makefile
• ... a container image?! 0_o
Package is...
6
DevOpsDays Warsaw 2019
Package is a distributable set of idempotent alternations
bringing desired artefacts and state changes to a target
system.
7
DevOpsDays Warsaw 2019
Containerisation is a form of packaging – the rules apply.
8
DevOpsDays Warsaw 2019
Delivery pipeline
Source code
0 1 0
1 0 1
1 1 0
Build
toolchain
Artefacts
Build
dependencies
Runtime
dependencies
Packaging
toolchain
Package
9
DevOpsDays Warsaw 2019
Target platforms
MutableImmutable
• Artefacts
• Configuration
• Dependencies
• Artefacts
• Configuration
• List of
dependencies
Runtime
depencencies
Fetch
10
DevOpsDays Warsaw 2019
Target platforms
Runtime dependencies are
available in vendor repositories.
Runtime dependencies are
shipped within the package.
11
DevOpsDays Warsaw 2019
• Supporting the community was not #1 priority
12
DevOpsDays Warsaw 2019
Solution:
1. Create a single pipeline for the community and ourselves
2. Pack the same artefacts into different packages
13
DevOpsDays Warsaw 2019
Target platforms
14
DevOpsDays Warsaw 2019
0 1
1 0
0 1
1 0
15
DevOpsDays Warsaw 2019
• cPython 3.4+
• Database drivers + other shared libraries
• Required python libraries
• ...
• Django-*
Runtime dependencies
16
DevOpsDays Warsaw 2019
Deb package
Artefacts:
1. Python code
2. Static files
3. Configuration
Runtime dependencies:
1. python-3
2. mysql-common
3. ...
4. python3-mysql
5. python3-django
6. python3-*
17
DevOpsDays Warsaw 2019
Never run pip install on a target system.
18
DevOpsDays Warsaw 2019
• Copy dependencies to the source tree
• Keeping wheels in the source tree
• Package a virtual environment 0_o
• No source-code changes required
• Use standard management tools
• Gradual migration to system packages
Other options?
19
DevOpsDays Warsaw 2019
• Create one
• Install python stuff
• Required packages
• Source code
• Fix the symlinks
• Pack the virtualenv into the deb package
Virtualenv
20
DevOpsDays Warsaw 2019
dh_virtualenv does all of that for you!
debian/control:
21
DevOpsDays Warsaw 2019
dh_virtualenv does all of that for you!
debian/rules:
22
DevOpsDays Warsaw 2019
• Use all matching requirements from the vendor's
repository
• Use dh_virtualenv
• Put the rest of the requirements along with the source code into the
virtualenv
• Gradually migrate the code to the libraries available in the vendor's
repositories
Deb package – summary
23
DevOpsDays Warsaw 2019
Docker image – extra layer of complexity
• Supporting different container orchestrators
• Configuration without breaking immutability
• Performing operations without entering running containers
• Serving static files
24
DevOpsDays Warsaw 2019
• Single entry point script
• Avoid exposing the filesystem structure
• Acts like a facade for all entry points
• By default starts the service
Startup and operations
25
DevOpsDays Warsaw 2019
• Select few essential configuration options and define
environment variables for each
• The entry point script puts the values of those variables
into configuration files
• Those in need of supplying advanced configuration should mount the
entire configuration as a volume
Configuration
26
DevOpsDays Warsaw 2019
• Build a separate image with static files
• Use a lightweight image like nginx as a base
• Users will route requests to one of the containers depending
on the container orchestrator
Static files
27
DevOpsDays Warsaw 2019
• Custom entry point acting like a facade
• Essential configuration options as environment variables
• Advanced configuration is done by mounting configuration
as a volume
• Static files are available in a separate image
• Publish both images at the same time
Docker image – summary
28
DevOpsDays Warsaw 2019
Conclusion
29
DevOpsDays Warsaw 2019
Support opinionated scenarios based on in-house usage.
30
DevOpsDays Warsaw 2019
Improve things gradually.
31
DevOpsDays Warsaw 2019
Be ready to say goodbye to corner-case users to make
the vast majority happy.
32
DevOpsDays Warsaw 2019
Does not matter what decisions you make, unless they are
irreversible.
33
DevOpsDays Warsaw 2019
Thank you!
34
Roman Prykhodchenko, Allegro
@romcheg
me@romcheg.me
I'm waiting for
your feedback!
You can rate speakers and lectures
using our official conference app

More Related Content

PDF
Docker Containers Deep Dive
PDF
Managing Open Source software in the Docker era
PDF
CNCF Projects Overview
PDF
PyWPS-4.0.0
PDF
321 codeincontainer brewbox
PPTX
Introduction into Docker Containers, the Oracle Platform and the Oracle (Nati...
PPTX
Intro to Docker at the 2016 Evans Developer relations conference
PDF
Introduction to containers running dockers using kubernetes - הרצאה לכנס מיק...
Docker Containers Deep Dive
Managing Open Source software in the Docker era
CNCF Projects Overview
PyWPS-4.0.0
321 codeincontainer brewbox
Introduction into Docker Containers, the Oracle Platform and the Oracle (Nati...
Intro to Docker at the 2016 Evans Developer relations conference
Introduction to containers running dockers using kubernetes - הרצאה לכנס מיק...

What's hot (20)

PPTX
DockerCon EU 2015: Docker Universal Control Plane (Gordon's Special Session)
PDF
WSO2Con ASIA 2016: Revolutionizing WSO2 App Cloud with Kubernetes & Docker
PPTX
Microcontainers and Tools for Hardcore Container Debugging
PDF
Docker based-pipelines
PPTX
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
PDF
July OpenNTF Webinar - HCL Presents Keep, a new API for Domino
PPTX
Docker Online Meetup #30: Docker Trusted Registry 1.4.1
PPTX
Docker Overview - AWS Tech Connect - Seattle 10/28
PPTX
Introduction to Docker
PPTX
The Art and Zen of Managing Nagios With Puppet
PPTX
What is Kafka & why is it Important? (UKOUG Tech17, Birmingham, UK - December...
PDF
Informix on Docker Hub
PPTX
Using Docker in production: Get started today!
PDF
Introduction to Docker | Docker and Kubernetes Training
PPTX
Moving Legacy Applications to Docker by Josh Ellithorpe, Apcera
PPTX
.docker : How to deploy Digital Experience in a container, drinking a cup of ...
PDF
IIUG 2017 Conference - Informix and Docker
PPTX
DockerCon EU 2015 Barcelona
PPTX
Docker - A curtain raiser to the Container world
PDF
Docker Hub Breakout Session at DockerCon by Ken Cochrane
DockerCon EU 2015: Docker Universal Control Plane (Gordon's Special Session)
WSO2Con ASIA 2016: Revolutionizing WSO2 App Cloud with Kubernetes & Docker
Microcontainers and Tools for Hardcore Container Debugging
Docker based-pipelines
Docker Hub: Past, Present and Future by Ken Cochrane & BC Wong
July OpenNTF Webinar - HCL Presents Keep, a new API for Domino
Docker Online Meetup #30: Docker Trusted Registry 1.4.1
Docker Overview - AWS Tech Connect - Seattle 10/28
Introduction to Docker
The Art and Zen of Managing Nagios With Puppet
What is Kafka & why is it Important? (UKOUG Tech17, Birmingham, UK - December...
Informix on Docker Hub
Using Docker in production: Get started today!
Introduction to Docker | Docker and Kubernetes Training
Moving Legacy Applications to Docker by Josh Ellithorpe, Apcera
.docker : How to deploy Digital Experience in a container, drinking a cup of ...
IIUG 2017 Conference - Informix and Docker
DockerCon EU 2015 Barcelona
Docker - A curtain raiser to the Container world
Docker Hub Breakout Session at DockerCon by Ken Cochrane
Ad

Similar to Packaging a Python application after you messed up - Roman Prykhodchenko (20)

PDF
Upgrading CentOS on the Facebook fleet
PDF
The Latest Status of CE Workgroup Shared Embedded Linux Distribution Project
PPTX
Symfony under control. Continuous Integration and Automated Deployments in Sy...
PPTX
Symfony Under Control by Maxim Romanovsky
PDF
CentOS Stream at Facebook
PPTX
Getting Started with Docker
ODP
Unicon Nov 2014 IAM Briefing
PPTX
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
PDF
Lightweight Virtualization Docker in Practice
ODP
Docker for Developers - PHP Detroit 2018
PDF
Docker in pratice -chenyifei
PDF
Alibaba Cloud Conference 2016 - Docker Open Source
PDF
Effectively using Open Source with conda
PDF
DockerCon Recap - Online Meetup by Ben Firshman
PDF
Bring Your Own Container: Using Docker Images In Production
PPTX
Modern .NET Ecosystem
PPTX
Intro Docker october 2013
PPTX
Short-Training asp.net vNext
PPTX
Moby KubeCon 2017
PDF
O365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
Upgrading CentOS on the Facebook fleet
The Latest Status of CE Workgroup Shared Embedded Linux Distribution Project
Symfony under control. Continuous Integration and Automated Deployments in Sy...
Symfony Under Control by Maxim Romanovsky
CentOS Stream at Facebook
Getting Started with Docker
Unicon Nov 2014 IAM Briefing
Write Once and REALLY Run Anywhere | OpenStack Summit HK 2013
Lightweight Virtualization Docker in Practice
Docker for Developers - PHP Detroit 2018
Docker in pratice -chenyifei
Alibaba Cloud Conference 2016 - Docker Open Source
Effectively using Open Source with conda
DockerCon Recap - Online Meetup by Ben Firshman
Bring Your Own Container: Using Docker Images In Production
Modern .NET Ecosystem
Intro Docker october 2013
Short-Training asp.net vNext
Moby KubeCon 2017
O365Con19 - Sharing Code Efficiently in your Organisation - Elio Struyf
Ad

Recently uploaded (20)

DOCX
search engine optimization ppt fir known well about this
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
Getting Started with Data Integration: FME Form 101
PDF
Hybrid model detection and classification of lung cancer
PPTX
observCloud-Native Containerability and monitoring.pptx
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PPTX
Modernising the Digital Integration Hub
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
August Patch Tuesday
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Architecture types and enterprise applications.pdf
PPT
Geologic Time for studying geology for geologist
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPTX
The various Industrial Revolutions .pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Chapter 5: Probability Theory and Statistics
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
search engine optimization ppt fir known well about this
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
Getting Started with Data Integration: FME Form 101
Hybrid model detection and classification of lung cancer
observCloud-Native Containerability and monitoring.pptx
Web Crawler for Trend Tracking Gen Z Insights.pptx
Modernising the Digital Integration Hub
Developing a website for English-speaking practice to English as a foreign la...
August Patch Tuesday
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
A contest of sentiment analysis: k-nearest neighbor versus neural network
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Architecture types and enterprise applications.pdf
Geologic Time for studying geology for geologist
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
The various Industrial Revolutions .pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Zenith AI: Advanced Artificial Intelligence
Chapter 5: Probability Theory and Statistics
How ambidextrous entrepreneurial leaders react to the artificial intelligence...

Packaging a Python application after you messed up - Roman Prykhodchenko

  • 1. Packaging a Python application after you messed up Roman Prykhodchenko, Allegro @romcheg me@romcheg.me November 2019, Warsaw www.devopsdays.pl
  • 2. DevOpsDays Warsaw 2019 • Maintained and used in house • Heavily modified django-admin • Python + HTML + JS • Open-source + private extensions • In house: Ubuntu + Docker image • In community: mostly Ubuntu + deb package but.... DCIM system: Ralph 2
  • 3. DevOpsDays Warsaw 2019 Problem • Community builds are often broken • Troubleshooting takes more time than we have • No motivation to support the community 3
  • 4. DevOpsDays Warsaw 2019 Reasons • Two separate delivery pipelines • TravisCI: Debian package built and published once a week • Bamboo: Docker image with private extensions available on demand • Different artefacts in community and local packages • Supporting the community is not the team's #1 priority 4
  • 5. DevOpsDays Warsaw 2019 Solution: Improve the delivery pipeline by re-thinking packaging. 5
  • 6. DevOpsDays Warsaw 2019 • ... a file with an .rpm or .deb in the end • ... a python wheel • ... a tarball with a source code and a Makefile • ... a container image?! 0_o Package is... 6
  • 7. DevOpsDays Warsaw 2019 Package is a distributable set of idempotent alternations bringing desired artefacts and state changes to a target system. 7
  • 8. DevOpsDays Warsaw 2019 Containerisation is a form of packaging – the rules apply. 8
  • 9. DevOpsDays Warsaw 2019 Delivery pipeline Source code 0 1 0 1 0 1 1 1 0 Build toolchain Artefacts Build dependencies Runtime dependencies Packaging toolchain Package 9
  • 10. DevOpsDays Warsaw 2019 Target platforms MutableImmutable • Artefacts • Configuration • Dependencies • Artefacts • Configuration • List of dependencies Runtime depencencies Fetch 10
  • 11. DevOpsDays Warsaw 2019 Target platforms Runtime dependencies are available in vendor repositories. Runtime dependencies are shipped within the package. 11
  • 12. DevOpsDays Warsaw 2019 • Supporting the community was not #1 priority 12
  • 13. DevOpsDays Warsaw 2019 Solution: 1. Create a single pipeline for the community and ourselves 2. Pack the same artefacts into different packages 13
  • 15. DevOpsDays Warsaw 2019 0 1 1 0 0 1 1 0 15
  • 16. DevOpsDays Warsaw 2019 • cPython 3.4+ • Database drivers + other shared libraries • Required python libraries • ... • Django-* Runtime dependencies 16
  • 17. DevOpsDays Warsaw 2019 Deb package Artefacts: 1. Python code 2. Static files 3. Configuration Runtime dependencies: 1. python-3 2. mysql-common 3. ... 4. python3-mysql 5. python3-django 6. python3-* 17
  • 18. DevOpsDays Warsaw 2019 Never run pip install on a target system. 18
  • 19. DevOpsDays Warsaw 2019 • Copy dependencies to the source tree • Keeping wheels in the source tree • Package a virtual environment 0_o • No source-code changes required • Use standard management tools • Gradual migration to system packages Other options? 19
  • 20. DevOpsDays Warsaw 2019 • Create one • Install python stuff • Required packages • Source code • Fix the symlinks • Pack the virtualenv into the deb package Virtualenv 20
  • 21. DevOpsDays Warsaw 2019 dh_virtualenv does all of that for you! debian/control: 21
  • 22. DevOpsDays Warsaw 2019 dh_virtualenv does all of that for you! debian/rules: 22
  • 23. DevOpsDays Warsaw 2019 • Use all matching requirements from the vendor's repository • Use dh_virtualenv • Put the rest of the requirements along with the source code into the virtualenv • Gradually migrate the code to the libraries available in the vendor's repositories Deb package – summary 23
  • 24. DevOpsDays Warsaw 2019 Docker image – extra layer of complexity • Supporting different container orchestrators • Configuration without breaking immutability • Performing operations without entering running containers • Serving static files 24
  • 25. DevOpsDays Warsaw 2019 • Single entry point script • Avoid exposing the filesystem structure • Acts like a facade for all entry points • By default starts the service Startup and operations 25
  • 26. DevOpsDays Warsaw 2019 • Select few essential configuration options and define environment variables for each • The entry point script puts the values of those variables into configuration files • Those in need of supplying advanced configuration should mount the entire configuration as a volume Configuration 26
  • 27. DevOpsDays Warsaw 2019 • Build a separate image with static files • Use a lightweight image like nginx as a base • Users will route requests to one of the containers depending on the container orchestrator Static files 27
  • 28. DevOpsDays Warsaw 2019 • Custom entry point acting like a facade • Essential configuration options as environment variables • Advanced configuration is done by mounting configuration as a volume • Static files are available in a separate image • Publish both images at the same time Docker image – summary 28
  • 30. DevOpsDays Warsaw 2019 Support opinionated scenarios based on in-house usage. 30
  • 31. DevOpsDays Warsaw 2019 Improve things gradually. 31
  • 32. DevOpsDays Warsaw 2019 Be ready to say goodbye to corner-case users to make the vast majority happy. 32
  • 33. DevOpsDays Warsaw 2019 Does not matter what decisions you make, unless they are irreversible. 33
  • 35. Roman Prykhodchenko, Allegro @romcheg me@romcheg.me I'm waiting for your feedback! You can rate speakers and lectures using our official conference app

Editor's Notes

  • #2: Let me just brief you quickly with the background -- I am an engineer in a team supporting certain part of the technical platform at our company and our team had a problem!
  • #3: Running our services requires an extensive infrastructure built with a few thousands of assets. In order to handle that we have created a DCIM Ralph with the main goal to be the software that fulfils our internal needs. At some point of time it was published under apache license just because... somehow it gained some popularity
  • #5: For the company Ralph is not a product therefore the team's focus must stay on the in-house needs, including maintenance of other systems. Open-sourcing this sort of software is debatable, yet here we are and there's no way back.
  • #8: distributable --
  • #9: That means all the constraints apply.
  • #11: Immutable -- you should supply runtime dependencies Mutable -- you may fetch dependencies from a trusted source
  • #13: Then we gave it another thought and realised the cornerstone of the mess is the last issue and as the matter of fact it's the only one from the list we cannot fix since it is a direct consequence of the business model of the company. Following the DevOps philosophy means taking responsibility for more then just the development, so we could not ignore that.
  • #14: The basic idea was that whatever is given to the community should be also used by us.
  • #15: That required to make several unpopular, yet necessary changes in the initial plan -- and the first of them was to sacrifice the idea of RPM builds. Moreover -- we had to select only one Debian-based distribution of GNU/Linux which is used in the vast majority of use cases.
  • #17: Django application often ends up being dependent on a ton of libraries from the Django ecosystem and the combination often works only when all requirements have very specific range of versions.
  • #18: External python libraries are available in canonical's repositories under certain names. Canonical maintains those packages and provides patches and security updates Yet those libraries have specific versions that won't match the requirements of the python code. There's a way to install python libraries -- pip install/easy_install -- installs from PyPi/other repos. With django that's a huge problem.
  • #19: Python package management is non deterministic -- requirements do not have strict versions, you never know what gets installed on the target system. Even if you freeze the dependency tree: Installing python packages may require build tools to compile extensions written in C. Random failures We have to bring those requirements inside the package.
  • #20: huge source tree, long installation, more c-libraries required, changes in the source code may be necessary to fix imports Complicated installation process, more steps to update requirements, cannot use standard python package management tools Seems funny, but... Good as a transitional stage
  • #21: Therefore it is necessary to add some sort of script to the pipeline that will do the following steps: Sounds like too much of a hustle for a transitional stage.
  • #25: When designing a container image, it is necessary to keep in mind that "docker run" is not how containers are often run on production. Container orchestrators like "Kubernetes" or even simple "docker-compose" require some work to be done before an image can be actually used. Docker isolates what's inside, yet it's often necessary to get under the hood, e.g. to configure the software or to perform different operations.
  • #28: Since static files are inside the container, serving them won't be as easy
  • #31: To summarise – when open-sourcing your software while the human-power is limited or when priorities do not put community to the 1st place follow these 3 strategies: Well done opinionated software is much better than weak one that provides many options.
  • #32: Trying to start with a "by the book" approach is likely to be too time consuming or too expensive.
  • #33: Be ready to receive tons of negative feedback or anger.