Slide 1

Slide 1 text

Applied Buildout Gary Walker

Slide 2

Slide 2 text

Overview What is buildout? What problems can it solve? How do I use it? How do I get it running in production?

Slide 3

Slide 3 text

What is Buildout?

Slide 4

Slide 4 text

buildout Write code Install dependencies Freeze dependencies Distribute list of dependencies Write code Configure dependencies Run buildout Distribute config file virtualenv/pip virtualenv vs buildout - development

Slide 5

Slide 5 text

virtualenv vs buildout - installation buildout Clone repository Create virtualenv pip install packages Download buildout.cfg Run bootstrap.py Run bin/buildout virtualenv/pip

Slide 6

Slide 6 text

Example Buildout Config [buildout] parts = myapp [myapp] recipe = zc.recipe.egg eggs = something-from-pypi

Slide 7

Slide 7 text

Getting a Clean Environment

Slide 8

Slide 8 text

Bootstrapping - Windows http://downloads.buildout.org/2/bootstrap.py Inside the domain: \\share\buildout\bootstrap.bat Uses a version of Python installed by Group Policy Outside the domain: powershell -command (new-object System.Net.WebClient). Downloadfile(\"http://shapeset/buildout/bootstrap/bootstrap. py\", \"bootstrap.py\")

Slide 9

Slide 9 text

Bootstrapping - POSIX curl http://share/buildout/bootstrap.py > bootstrap.py

Slide 10

Slide 10 text

Further Information Brandon Rhodes, “A Brief Introduction to Buildout” http://www.youtube.com/watch?v=HXvzzK9m2IA Benoit Bryan, “From pip+virtualenv to buildout” http://www.marmelune.net/en/python/buildout/from- virtualenv-to-buildout/

Slide 11

Slide 11 text

What Problems Can it Solve?

Slide 12

Slide 12 text

Build-System Code in Every Branch

Slide 13

Slide 13 text

Semantic Versioning Given a version number MAJOR.MINOR. PATCH, increment the: 1. MAJOR version a. when you make incompatible API changes, 2. MINOR version a. when you add functionality in a backwards- compatible manner, and 3. PATCH version a. when you make backwards-compatible bug fixes. b.

Slide 14

Slide 14 text

Semantic Versioning in Practice [buildtools] recipe = zc.recipe.egg eggs = hurf < 1 durf < 2

Slide 15

Slide 15 text

Extending Buildout with Recipes

Slide 16

Slide 16 text

Artifact Repository Recipe [clientdata] recipe = artifactrepo.recipe project = clientdatapackage version = 2.3 destination = ../../clientdata_directory

Slide 17

Slide 17 text

Artifact Repository Recipe def update(self): new_file_info = self.get_download_info() existing_file_info = self.get_update_info() if new_file_info != existing_file_info: self.install()

Slide 18

Slide 18 text

Artifact Repository Recipe def get_download_info(self): url_params = { 'project': self.options['project'], 'version': self.options.get('version', ''), url = REPO_URL + urlencode(url_params) return urlopen(url).read()

Slide 19

Slide 19 text

Artifact Repository Recipe def install(self): file_info = self.get_download_info() destination_dir = self.options.get('destination') if not os.path.isdir(destination_dir): os.makedirs(destination_dir) # cache info about file so we can check in update() json.dump(file_info, open(self.update_info_path, 'w')) self.download_file(file_info['file_path'])

Slide 20

Slide 20 text

Production Infrastructure

Slide 21

Slide 21 text

Config-file Inheritance

Slide 22

Slide 22 text

Config Variable Substitution ${sectionname:optionname} Works up and down inheritance chain

Slide 23

Slide 23 text

Config-file Inheritance: base.cfg [buildout] show-picked-versions = true find-links = http://egg/repository

Slide 24

Slide 24 text

Config-file Inheritance: base-dev.cfg [buildout] extends = http://configs/base.cfg eggs = ${buildout.package} develop = . parts = app nose [nose] recipe = pbp.recipe.noserunner eggs = ${buildout.eggs} [app] recipe = zc.recipe.egg eggs = ${buildout.eggs}

Slide 25

Slide 25 text

Config-file Inheritance: app.cfg [buildout] package = myapp extends = http://configs/base-dev.cfg

Slide 26

Slide 26 text

Buildout bootstrap.py -v 1.2.3 distribute/setuptools ● point bootstrap.py to custom distribute setup script ● hardcode distribute version in that setup script Resilience Against Buildout/Distribute Code Changes

Slide 27

Slide 27 text

Resilience against PyPI downtime https://pypi.python.org/pypi/proxypypi $ pip install proxypypi $ cd cachedir $ proxypypi run [buildout] index = http://pypi-proxy-machine/simple/