Top Banner
IDAN GAZIT PyWeb-IL 10, Nov 30 th 2009 repeatable INSTALLS and DEPLOYMENTS PIP, VIRTUALENV and FABRIC
56

Repeatable Deployments and Installations

May 13, 2015

Download

Technology

Idan Gazit

Using virtualenv, pip, and fabric
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Repeatable Deployments and Installations

IDAN GAZITPyWeb-IL 10, Nov 30th 2009

repeatable INSTALLS and DEPLOYMENTSPIP, VIRTUALENV and FABRIC

Page 2: Repeatable Deployments and Installations

HOORAY.

SO YOU HAVE A PROJECT

Page 3: Repeatable Deployments and Installations

NEW DEVELOPERNEW SERVERNEW VERSION

NOW YOU HAVE A

Page 4: Repeatable Deployments and Installations

NEW DEVELOPERSNEW SERVERSNEW VERSIONS

NOW YOU HAVE A HUNDRED

Page 5: Repeatable Deployments and Installations

MAKING SHIT

OVERHEAD

Page 7: Repeatable Deployments and Installations

KILL IT FIRST

THE OVERHEAD WILL KILL YOU

Page 8: Repeatable Deployments and Installations

ANY MORE AND YOU'RE F*CKED

ONE CLICK

Page 9: Repeatable Deployments and Installations

THESE TOOLS WILL HELP

ELIMINATE OVERHEAD

Page 10: Repeatable Deployments and Installations

PULL TOGETHER ALL THE PARTS OF YOUR APPREPEATABILITY

O(1) DEPLOYMENTSSCALABILITY

PROTECT YOUR APP FROM OTHER APPSISOLATION

Page 11: Repeatable Deployments and Installations

by IAN BICKING

VIRTUALENV

Page 13: Repeatable Deployments and Installations

NOT REALLY.

LIKE GOGGLES FOR YOUR PYTHON

Page 14: Repeatable Deployments and Installations

"PRIVATE" SITE-PACKAGES

ISOLATED PYTHON ENVIRONMENTS

Page 15: Repeatable Deployments and Installations

APP X APP YFOO 0.8

BAR 1.23BAZ 6.0c9

BLAH 2.2BAR 1.23

BLING 9.1b2

Page 16: Repeatable Deployments and Installations

APP X APP YFOO 0.8

BAR 1.23BAZ 6.0c9

BLAH 2.2BAR 1.24

BLING 9.1b2

Page 17: Repeatable Deployments and Installations

LIKE A VIRGIN

GLOBAL SITE-PACKAGES

Page 18: Repeatable Deployments and Installations

CREATE THE VIRTUALENV

$ python virtualenv.py ENV

Page 19: Repeatable Deployments and Installations

COMPLETE ISOLATION

--no-site-packages

Page 20: Repeatable Deployments and Installations

A FEW GLOBAL PACKAGES (IPYTHON, IPDB)

ME, PERSONALLY?

Page 21: Repeatable Deployments and Installations

TO ENTER THE MATRIX

$ source ENV/bin/activate

Page 22: Repeatable Deployments and Installations

WOAH.

(ENV)$ easy_install kungfu

Page 23: Repeatable Deployments and Installations

I CAN DODGE BULLETS

(ENV)$ python theone.py

Page 24: Repeatable Deployments and Installations

OPERATOR, I NEED AN EXIT!

(ENV)$ deactivate

Page 25: Repeatable Deployments and Installations

DIFFERENT VERSIONS OF THE SAME APP

MORE USE CASES

Page 26: Repeatable Deployments and Installations

SETUP THE SAME VIRTUALENV

DEPLOYING?

Page 27: Repeatable Deployments and Installations

IT'S JUST PYTHONPATH

WEB APPS

Page 28: Repeatable Deployments and Installations

YOU GOTTA KEEP'EM SEPARATED

INDEPENDENT VIRTUALENV

Page 30: Repeatable Deployments and Installations

by DOUG HELLMANN

VIRTUALENVWRAPPER

Page 31: Repeatable Deployments and Installations

$ mkvirtualenv ENV$ workon ENV

Page 32: Repeatable Deployments and Installations

also by IAN BICKING

PIP

Page 33: Repeatable Deployments and Installations

GOODBYE, EASY_INSTALL

PIP INSTALLS PACKAGES

Page 34: Repeatable Deployments and Installations

NO PARTIAL INSTALLSNON-SUCKY CONSOLE OUTPUT

INSTALL FROM VCSREQUIREMENTS FILES

UNINSTALL

SMARTER

Page 35: Repeatable Deployments and Installations

PIP is VIRTUALENV-AWARE

$(ENV) pip install -E ENV mypackage

Page 36: Repeatable Deployments and Installations

BOOM. I HAZ REQUIREMENTZ FILE.

$(ENV) pip freeze -E ENV > reqs.txt

Page 37: Repeatable Deployments and Installations

SIT BACK AND RELAX

$(ENV) pip install -E ENV -r reqs.txt

Page 38: Repeatable Deployments and Installations

FRAMEWORK==0.2LIBRARY>=1.3

-e svn+http://myrepo/svn/MyApp#egg=MyApp

REQUIREMENTS FILE

Page 39: Repeatable Deployments and Installations

SUBVERSIONGIT

MERCURIALBAZAAR

SUPPORTED VCS's

Page 40: Repeatable Deployments and Installations

1. PULL FROM VCS2. CREATE VENV

3. PIP INSTALL FROM REQUIREMENTS FILE4. THERE IS NO STEP FOUR

FRESH DEPLOY

Page 41: Repeatable Deployments and Installations

http://www.flickr.com/photos/an-di/274127482

ROCKSTAR.

Page 42: Repeatable Deployments and Installations

4 STEPS IS 3 STEPS TOO MANY

NOT SO FAST

Page 43: Repeatable Deployments and Installations

maintained by JEFF FORCIER

FABRIC

Page 44: Repeatable Deployments and Installations

REMOTE COMMANDS OVER SSH(LOCAL COMMANDS TOO)

AUTOMATE

Page 45: Repeatable Deployments and Installations

EXCEPT PYTHONIC AND DELICIOUS

IT'S KIND OF LIKE ‘MAKE'

Page 46: Repeatable Deployments and Installations

FABFILE.PY

Page 47: Repeatable Deployments and Installations

FABFILE.PYfrom __future__ import with_statementfrom fabric.api import *

env.hosts = ['server1.foo.com', 'server2.foo.com']

def test(): with settings(warn_only=True): result = local('./manage.py test my_app', capture=False) if result.failed: abort("Aborting at user request.")

def pack(): local('tar czf /tmp/my_project.tgz .', capture=False)

def prepare(): test() pack()

def deploy(): put('/tmp/my_project.tgz', '/tmp/') with cd('/srv/django/my_project/'): run('tar xzf /tmp/my_project.tgz') run('touch app.wsgi')

Page 48: Repeatable Deployments and Installations

RUNS test() AND pack()

$ fab prepare

Page 49: Repeatable Deployments and Installations

ONE STEP NIRVANA.

$ fab prepare deploy

Page 50: Repeatable Deployments and Installations

FABFILE.PY

from __future__ import with_statementfrom fabric.api import *

def staging(): env.hosts = ['staging.foo.com']

def production(): env.hosts = ['prod1.foo.com', 'prod2.foo.com']

# ... more fab actions ...

def deploy(): put('/tmp/my_project.tgz', '/tmp/') with cd('/srv/django/my_project/'): run('tar xzf /tmp/my_project.tgz') run('touch app.wsgi')

Page 51: Repeatable Deployments and Installations

DEPLOY TO STAGING IN ONE LINE

$ fab staging deploy

Page 52: Repeatable Deployments and Installations

LOCALRUN

SUDOGET/PUTPROMPT

FABRIC BUILTINS

Page 53: Repeatable Deployments and Installations

REPEATABLE DEPENDENCY INSTALLSPIP

FOR AUTOMATED DEPLOYMENTSFABRIC

TO ISOLATE YOUR PROJECTVIRTUALENV

Page 55: Repeatable Deployments and Installations

QUESTIONS?

Page 56: Repeatable Deployments and Installations

@[email protected]

http://bit.ly/repeatable-deployments

THANK YOU!