Fabric

16
fabric – deployment tool jslee

description

 

Transcript of Fabric

Page 1: Fabric

fabric – deployment tool

jslee

Page 2: Fabric

When I was in Yahoo!

• yinst impackage.tgz –h host[1-10]• yinst yphp –upgrade v5.0 –h host[1-10] –

dist dist.corp.yahoo.com• yinst yphp –downgrade v4.0 –h host[1-10]

–dist dist.corp.yahoo.com

• yinst – write in perl a deployment tool

Page 3: Fabric

Reinventing the wheel?

Page 4: Fabric

in python

• pip -  is a tool for installing and managing Python packages

• virtualenv - is a tool to create isolated Python environments.

• fabric -  is a Python (2.5 or higher) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.

Page 5: Fabric

in Ruby

• RVM • Bundler • Capistrano

Page 6: Fabric

Why need deployment tool?

• Don't repeat yourself• 1 human vs 1 Million machine• once and only once

Page 7: Fabric

coding now!

• #fabfile.py• from fabric.api import run • def host_type(): • run('uname -s')

Page 8: Fabric

Execute now!

• $ fab -H localhost,linuxbox host_type [localhost] run: uname -s

• [localhost] out: Darwin

• [linuxbox] run: uname -s

• [linuxbox] out: Linux

• Done.

• Disconnecting from localhost... done.

• Disconnecting from linuxbox... done.

Page 9: Fabric

• thats it !

Page 10: Fabric

its python code so

• 1. genrente hosts list by code• for i in range(1, 11):• env.hosts.append("host" + str(i))

Page 11: Fabric

• 2. use @parallel Decorator polling task• @parallel(pool_size=2)• def hello():• import time• sudo('uptime')• time.sleep(3)

Page 12: Fabric

• 3.use @roles grouping ur hosts• @roles('web')• def hello_web():• run('uptime')• @roles('db')• def hello_db():• run('uptime')

Page 13: Fabric

• 4.use python library in task:• import github2.client• def _get_my_forks():• #auto save user_name as .username• user_name = None• if os.path.isfile("./.username"):• f = open('./.username', 'r')• user_name = str(f.readline()).strip()• user_name = prompt(color.green("Enter your github user name :

"), default=user_name)• f = open('./.username', 'w')• f.write(user_name)• f.close()

Page 14: Fabric

others example

• 5. fab --list • Available commands:

• apache_reload reload Apache on remote host

• apache_restart restart Apache on remote host

• bootstrap initialize remote host environment (virtualenv, dep...

• configtest Apache configuration

• create_virtualenv setup virtualenv on remote host

• deploy rsync code to remote host

• production use production environment on remote host

• staging use staging environment on remote host

• symlink_django create symbolic link so Apache can serve django adm...

• touch touch wsgi file to trigger reload

• update_apache_conf upload apache configuration to remote host

• update_requirements update external dependencies on remote host

Page 15: Fabric

my-forks

• https://github.com/jsleetw/my-forks

• simply use (fab update) to sync your github forks repos with source repos 

Page 16: Fabric

• demo