Fabric
-
Upload
js-lee -
Category
Technology
-
view
448 -
download
0
description
Transcript of Fabric
![Page 1: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/1.jpg)
fabric – deployment tool
jslee
![Page 2: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/2.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/3.jpg)
Reinventing the wheel?
![Page 4: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/5.jpg)
in Ruby
• RVM • Bundler • Capistrano
![Page 6: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/6.jpg)
Why need deployment tool?
• Don't repeat yourself• 1 human vs 1 Million machine• once and only once
![Page 7: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/7.jpg)
coding now!
• #fabfile.py• from fabric.api import run • def host_type(): • run('uname -s')
![Page 8: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/9.jpg)
• thats it !
![Page 10: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/11.jpg)
• 2. use @parallel Decorator polling task• @parallel(pool_size=2)• def hello():• import time• sudo('uptime')• time.sleep(3)
![Page 12: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/12.jpg)
• 3.use @roles grouping ur hosts• @roles('web')• def hello_web():• run('uptime')• @roles('db')• def hello_db():• run('uptime')
![Page 13: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/13.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/14.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/15.jpg)
my-forks
• https://github.com/jsleetw/my-forks
• simply use (fab update) to sync your github forks repos with source repos
![Page 16: Fabric](https://reader036.fdocuments.net/reader036/viewer/2022082502/54993efab479598a0b8b4671/html5/thumbnails/16.jpg)
• demo