fabric – deployment tool
jslee
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
Reinventing the wheel?
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.
in Ruby
• RVM
• Bundler
• Capistrano
Why need deployment tool?
• Don't repeat yourself
• 1 human vs 1 Million machine
• once and only once
coding now!
• #fabfile.py
• from fabric.api import run
• def host_type():
• run('uname -s')
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.
• thats it !
its python code so
• 1. genrente hosts list by code
• for i in range(1, 11):
• env.hosts.append("host" + str(i))
• 2. use @parallel Decorator polling task
• @parallel(pool_size=2)
• def hello():
• import time
• sudo('uptime')
• time.sleep(3)
• 3.use @roles grouping ur hosts
• @roles('web')
• def hello_web():
• run('uptime')
• @roles('db')
• def hello_db():
• run('uptime')
• 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()
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
my-forks
• https://github.com/jsleetw/my-forks
• simply use (fab update) to sync your
github forks repos with source repos
• demo

Fabric

  • 1.
  • 2.
    When I wasin 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
  • 3.
  • 4.
    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.
  • 5.
    in Ruby • RVM •Bundler • Capistrano
  • 6.
    Why need deploymenttool? • Don't repeat yourself • 1 human vs 1 Million machine • once and only once
  • 7.
    coding now! • #fabfile.py •from fabric.api import run • def host_type(): • run('uname -s')
  • 8.
    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.
  • 9.
  • 10.
    its python codeso • 1. genrente hosts list by code • for i in range(1, 11): • env.hosts.append("host" + str(i))
  • 11.
    • 2. use@parallel Decorator polling task • @parallel(pool_size=2) • def hello(): • import time • sudo('uptime') • time.sleep(3)
  • 12.
    • 3.use @rolesgrouping ur hosts • @roles('web') • def hello_web(): • run('uptime') • @roles('db') • def hello_db(): • run('uptime')
  • 13.
    • 4.use pythonlibrary 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()
  • 14.
    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
  • 15.
    my-forks • https://github.com/jsleetw/my-forks • simplyuse (fab update) to sync your github forks repos with source repos
  • 16.