Fabric

616 views
568 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
616
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Fabric

  1. 1. fabric – deployment tooljslee
  2. 2. 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
  3. 3. Reinventing the wheel?
  4. 4. in python• pip - is a tool for installing and managingPython packages• virtualenv - is a tool to create isolatedPython environments.• fabric - is a Python (2.5 or higher) libraryand command-line tool for streamliningthe use of SSH for application deploymentor systems administration tasks.
  5. 5. in Ruby• RVM• Bundler• Capistrano
  6. 6. Why need deployment tool?• Dont repeat yourself• 1 human vs 1 Million machine• once and only once
  7. 7. coding now!• #fabfile.py• from fabric.api import run• def host_type():• run(uname -s)
  8. 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. 9. • thats it !
  10. 10. its python code so• 1. genrente hosts list by code• for i in range(1, 11):• env.hosts.append("host" + str(i))
  11. 11. • 2. use @parallel Decorator polling task• @parallel(pool_size=2)• def hello():• import time• sudo(uptime)• time.sleep(3)
  12. 12. • 3.use @roles grouping ur hosts• @roles(web)• def hello_web():• run(uptime)• @roles(db)• def hello_db():• run(uptime)
  13. 13. • 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()
  14. 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. 15. my-forks• https://github.com/jsleetw/my-forks• simply use (fab update) to sync yourgithub forks repos with source repos
  16. 16. • demo

×