There Should be One Obvious Way to Bring Python into Production - - PowerPoint PPT Presentation

there should be one obvious way to bring python into
SMART_READER_LITE
LIVE PREVIEW

There Should be One Obvious Way to Bring Python into Production - - PowerPoint PPT Presentation

There Should be One Obvious Way to Bring Python into Production Sebastian Neubauer sebastian.neubauer@blue-yonder.com @sebineubauer 1 Agenda What are we talking about and why? Delivery pipeline Dependencies Packaging What


slide-1
SLIDE 1

1

There Should be One Obvious Way to Bring Python into Production

Sebastian Neubauer

sebastian.neubauer@blue-yonder.com @sebineubauer

slide-2
SLIDE 2
  • What are we talking about and why?
  • Delivery pipeline
  • Dependencies
  • Packaging
  • What is the current state?
  • A walk through the different possibilities
  • Summarizing all the pros and cons
  • Can we fjnd a better solution?
  • How does the future look like?
  • Discussion: what could the „one obvious way“ be?

2

Agenda

slide-3
SLIDE 3

What are we talking about and why?

3

slide-4
SLIDE 4

4

Development Testing Building/Packaging Staging/QA

Production

Delivery pipeline

@sebineubauer

slide-5
SLIDE 5

5

Development Testing Building/Packaging Staging/QA

Production

Delivery pipeline

@sebineubauer

slide-6
SLIDE 6

6

Development

Required:

  • Fast iteration cycles, fast changes
  • Automated tests can be executed

Nice to have:

  • Production like local environment

Risks:

  • „Works on my machine!“
  • Dirty working directory

@sebineubauer

slide-7
SLIDE 7

7

Development Testing Building/Packaging Staging/QA

Production

Delivery pipeline

@sebineubauer

slide-8
SLIDE 8

8

Building/Packaging

Required:

  • Build once, use everywhere
  • Possibility to compile for the target systems
  • Build uniquely versioned, signed packages

Nice to have:

  • Upload to an artifact repository

Risks:

  • Misconfjguration of the build environment

@sebineubauer

slide-9
SLIDE 9

9

Development Testing Building/Packaging Staging/QA

Production

Delivery pipeline

@sebineubauer

slide-10
SLIDE 10

10

Testing

Required:

  • Automated
  • Near production like conditions
  • Reproducible conditions
  • Minimal changes for testing reasons

Nice to have:

  • Fast feedback
  • Running after each commit on all branches

Risks:

  • the tests test the test environment, but not production

@sebineubauer

slide-11
SLIDE 11

11

Development Testing Building/Packaging Staging/QA

Production

Delivery pipeline

@sebineubauer

slide-12
SLIDE 12

12

Staging/QA

Requirement:

  • Automated deploy in production like environment
  • Nearly no changes for testing purposes

Nice to have

  • A real clone of the production system
  • Possibility to run A/B tests on that system

Risks:

  • outdated, manually maintained setup

@sebineubauer

slide-13
SLIDE 13

13

Development Testing Building/Packaging Staging/QA

Production

Delivery pipeline

@sebineubauer

slide-14
SLIDE 14

14

Production

Required:

  • No compiler
  • No internet
  • Health monitoring

Nice to have:

  • Automated deploy
  • Automatic monitoring
  • Automatic self-healing
  • Automatic rolling update and roll back

Risks:

  • your business is going down…

@sebineubauer

slide-15
SLIDE 15

15

Development Testing Building/Packaging Staging/QA

Production

Developer’s Box Continuous integration server Modern cluster scheduler Good setup

@sebineubauer

slide-16
SLIDE 16

Bad setup

16

Development Testing Building/Packaging Staging/QA

Production

Developer’s Box Snowfmake pet server

@sebineubauer

slide-17
SLIDE 17

17

Dependencies

„All shared software components that need to be present in the correct version so that the application works correctly“

fjctitious defjnition

@sebineubauer

slide-18
SLIDE 18

18

Dependency Hell

Problems:

  • Transitive dependencies can have confmicting version

requirements

  • Python only knows application „global“ dependencies

(javascript has local dependencies)

  • Pip (still) doesn’t have proper dependency resolution (gh

#988 open since 11 Jun 2013, but GSoC 2017 project, fjngers crossed)

  • System python dependencies interfere with application

dependencies

@sebineubauer

slide-19
SLIDE 19

19

Package management in python

package manager: pip package format: wheel

  • still much confusion around setuptools, distutils, eggs…
  • many „best practices“ in stack overfmow & co. outdated
  • no standard templating for packages: see pyscaffold, versioneer…
  • feels like lack of interest in the community…
  • but: it has gotten way better in the last years:
  • setup.cfg
  • setuptools_scm

For details see: https://ep2017.europython.eu/conference/talks/python- packaging-current-state-and-overview by @webGandi

@sebineubauer

slide-20
SLIDE 20

20

Package manager hell

System dependencies Language dependencies

  • perating system, libraries

language specifjc libraries, frameworks yum, apt-get, homebrew, vcpks… pip, npm, conan, cpan, maven, composer, cargo, godep, gem,… frequent security updates almost no security updates „operations“ take care „developers“ take care root/system wide user space/virtualenv

@sebineubauer

slide-21
SLIDE 21

21

Package manager hell

System dependencies Language dependencies

  • perating system, libraries

language specifjc libraries, frameworks yum, apt-get, homebrew, vcpks… pip, npm, conan, cpan, maven, composer, cargo, godep, gem,… frequent security updates almost no security updates „infrastructure“ takes care „developers“ take care root/system wide user space/virtualenv

@sebineubauer

slide-22
SLIDE 22

22

Package manager hell

Where does it come from historically?

  • disk space and bandwidth expensive
  • separation between dev and ops
  • single language environments
  • rise of open source and sharing culture
  • no package manager solved everything

@sebineubauer

slide-23
SLIDE 23

What is the current state?

a walk through the different possibilities

23

slide-24
SLIDE 24

24

The classical approach

Development environment:

  • building proper python package (e.g. https://github.com/blue-yonder/

pyscaffold)

  • get everything somehow working: vagrant, conda, compile yourself…
  • pushing source to git

@sebineubauer

slide-25
SLIDE 25

25

The classical approach

On Jenkins:

  • building artifacts,
  • testing,
  • release: packaging (wheels) and publishing to an pypi compatible

artifact repository (artifactory, devpi…)

@sebineubauer

slide-26
SLIDE 26

26

The classical approach

In production:

  • standard virtualenv and pip
  • application gets installed from repo together with dependencies
  • OS and system dependencies are maintained separately

@sebineubauer

slide-27
SLIDE 27

27

The classical approach

Pro Con

  • „standard approch“
  • good and supported tooling
  • well understood
  • dependencies are resolved in production

again and again

  • need to build und upload wheels for all

binary packages to repository

  • because the dependencies are resolved „at

runtime“, developers must not forget to pin the dependencies

  • python only

@sebineubauer

slide-28
SLIDE 28

28

The „conserve virtualenv“ approach

  • idea: build a virtualenv, then pack it, ship it and unpack on the target

system

  • several similar implementations:
  • platter: simple virtualenv and wheels
  • pex: new virtualenv implementation, includes executed command
  • dh-virtualenv: virtualenvs packaged in debian packages
  • done once in build step

@sebineubauer

slide-29
SLIDE 29

29

The „conserve virtualenv“ approach

Pro Con

  • no resolving of dependencies on target

host

  • no dependency to a pypi server
  • „push or pull model“ possible, either you

copy the archive to the target, or it pulls from a repo

  • depending on the implementation (e.g.

platter) it integrates well in „standard“ workfmow with standard tools

  • system packages not included
  • need to compile for the exact target system
  • no standard repository:
  • implement push infrastructure
  • implement a repository (e.g. s3)
  • python only

@sebineubauer

slide-30
SLIDE 30

30

The OS package approach

  • idea: package the application as a standard OS package, e.g. debian

package

  • this way you can install the application with „apt-get install“ on the

target machines

  • deb package building is done once in the build step
  • there are some few tools that help you:
  • stdeb: build deb packages with one command (can’t get it to work, last commit

2 years ago :face_with_rolling_eyes:)

  • dh-virtualenv
  • for all dependencies, you either have to make deb packages too, or

you bundle them up (see dh-virtualenv)

@sebineubauer

slide-31
SLIDE 31

31

The OS package approach

Pro Con

  • integrates well with system maintenance
  • just one package manager needed
  • standard debian repository
  • tooling seems to be very badly maintained
  • no tooling for dependency management,

you have to create packages and declare the dependencies yourself (or use dh- virtualenv)

  • you need a debian repository
  • working with deb packages is often:

globally installed by root, not always what

  • ne needs

@sebineubauer

slide-32
SLIDE 32

32

The „container as PM“ approach

Developer’s box:

  • download a base image
  • provision the base image
  • develop the application in the container
  • commit the scripts for the provisioning and deploy in the container

@sebineubauer

slide-33
SLIDE 33

33

On Jenkins:

  • build the container image with the application baked in, using the

scripts

  • run the tests inside the container
  • if all tests pass, upload the image to the registry (artifactory, docker

registry…)

@sebineubauer

The „container as PM“ approach

slide-34
SLIDE 34

34

In production:

  • let the target hosts pull the image from the registry or push it to the

hosts

  • start it

@sebineubauer

The „container as PM“ approach

slide-35
SLIDE 35

35

Pro Con

  • good understood technology, de-facto

industry standard: schedulers, repositories, monitoring

  • complete decoupling from host OS,

windows, mac, jenkins or coreos in production, the application runs in the `==` same environment

  • complete environment+application is built
  • nce
  • everything in git
  • language independent
  • security updates on host irrelevant for

application

  • without proper processes and tooling, easy

to do it wrong: unapproved software in production, heartbleed…

  • dependency resolution and pypi server still

needed

  • chasm between system and language

dependencies still exists, but now in a container

  • doesn’t really reduce complexity

@sebineubauer

The „container as PM“ approach

slide-36
SLIDE 36

36

The „next packet manager“ approach

There are many (interesting) other package managers out there: Conda:

  • Python, R, Scala, Java, Javascript, C/ C++, FORTRAN
  • also packages system dependencies
  • works fmawlessly together with pip
  • easy to use
  • mature
  • so far no real on premise repository, but easy to implement

@sebineubauer

slide-37
SLIDE 37

37

The „next packet manager“ approach

Nix:

  • really interesting concept: purely declarative functional language for

expressing dependencies

  • immutable and git like behavior: uninstallation is a well defjned

rollback/revert

  • NixOS: completely removes the chasm between system and language

dependencies

  • language independent
  • lazy evaluation: dependencies only get installed if needed
  • not production ready yet…I guess…

@sebineubauer

slide-38
SLIDE 38

38

The „next packet manager“ approach

Pro Con

  • in the end it is a „package manager“

problem, so maybe there is a „next package manager“ that solves most of the problems

  • there are package managers that solve

parts of the problems even today (e.g. get numeric python packages working on mac and on windows using conda…)

  • a good end to end, language agnostic

package management solution has a huge potential

  • package management is only part of the

problem:

  • security updates
  • auditing
  • same environment for development,

testing and production

  • no end to end solution so far
  • very hard to get the critical mass needed

that it is a holistic solution for the whole problem for all languages

@sebineubauer

slide-39
SLIDE 39

39

The vendoring approach

  • Instead of depending on external libraries, you copy the source code

into your repository

  • you don't have any requirements (at least in your language)
  • you build just one big application package in one go
  • on the target system, you install one package with no dependencies
  • slightly similar to the „conserve virtualenv“ approach

@sebineubauer

slide-40
SLIDE 40

40

The vendoring approach

Pro Con

  • no dependency resolution at all
  • easy IDE code discovery
  • no dependecy to external repositories
  • easy to patch third party libraries
  • no dependency resolution at all, everything

needs to be done manually

  • hard work to keep it up to date
  • easier to patch third party libraries instead
  • f contributing and wait for release
  • dangerous licensing issues
  • useless for library development

@sebineubauer

slide-41
SLIDE 41

Can we fjnd a better solution?

41

slide-42
SLIDE 42

42

Containers are here to stay, for many reasons

How does the future look like?

@sebineubauer

slide-43
SLIDE 43

43

DevOps is the working mode

How does the future look like?

@sebineubauer

slide-44
SLIDE 44

44

Polyglott: the right language for the job

How does the future look like?

@sebineubauer

slide-45
SLIDE 45

45

Open source/sharing of code is increasing

How does the future look like?

@sebineubauer

slide-46
SLIDE 46

46

Automation is a must

How does the future look like?

@sebineubauer

slide-47
SLIDE 47

47

After that problem is solved, „serverless" becomes a thing

How does the future look like?

@sebineubauer

slide-48
SLIDE 48

And now a short discussion!

48

@sebineubauer

slide-49
SLIDE 49

Discussion

49

Classical/wheels Conserve virtualenv OS Package manager Container Next package manager Vendoring Other??

slide-50
SLIDE 50

Q&A

50

@sebineubauer

slide-51
SLIDE 51

51

Attributions

By BrokenSphere (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html) or CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons By Rl (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html), CC-BY-SA-3.0 (http://creativecommons.org/licenses/by-sa/3.0/) or CC BY-SA 2.5-2.0-1.0 (http://creativecommons.org/licenses/by-sa/2.5-2.0-1.0)], via Wikimedia Commons