Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Fabric-让部署变得简单
1. Fabric
Lo (Eric Lo)
http://lxneng.com
lxneng@gmail.com
twitter: @lxneng
Sunday, August 29, 2010
2. About
Fabric is a Python library and command-
line tool for streamlining the use of SSH
for application deployment or systems
administration tasks
capistrano in python
单 学 经
统
Sunday, August 29, 2010
3. Fabric is two things
Api for streamlining the use of ssh for
app development or system management
tasks
Command-line interface for calling
python methods
Sunday, August 29, 2010
4. Install
sudo easy_install fabric
Sunday, August 29, 2010
5. Example
vim fabfile.py
#!/usr/bin/env python
from fabric.api import env, run
env.hosts = ['xxx.com']
env.user = 'eric'
def du():
run("du -sh /home/eric")
Erics-MacBook:~ eric$ fab du
[xxx.com] run: du -sh /home/eric
[xxx.com] out: 942M
/home/eric
Done.
Disconnecting from xxx.com... done.
Sunday, August 29, 2010
6. Deploy my rails app
Erics-MacBook:~ eric$ cd NetBeans_Workspace/lxneng
Erics-MacBook:lxneng eric$ touch fabfile.py
Erics-MacBook:lxneng eric$ vim fabfile.py
#!/usr/bin/env python
# encoding: utf-8
from fabric.api import env, run, cd, local, put
env.hosts = ['192.168.1.5']
env.user = 'eric'
DEPLOY_PATH = '/var/www/'
APP_NAME = 'lxneng'
APP_PATH = '%s%s'%(DEPLOY_PATH, APP_NAME)
DATABASE_CONF_PATH = '/srv/conf/database.yml'
Sunday, August 29, 2010
11. Fabric Commands
• require: Make sure that certain environment variables
are available.
• prompt: Display a prompt to the user and store the input
in the given variable. Validation is optional.
• put: Upload files to the remote host(s).
• get: Download a file from a remote host.
• run: Run a shell command on the remote host(s).
• sudo: Run a root privileged shell command command on
the remote host(s).
• local: Run a command locally.
Sunday, August 29, 2010
12. Fabric Contrib Commands
• rsync_project: Synchronize a remote directory with the current project
directory via rsync.
• upload_project: Upload the current project to a remote system, tar-
gzipping during the move.
• exists: Return True if given path exists.
• first: Given one or more file paths, returns first one found, or None.
• upload_template: Render and upload a template text file to a remote host.
• sed: Run a search-and-replace on filename with given regex patterns.
• comment/uncomment: Attempt to (un)comment out all lines in filename
matching regex.
• contains: Return True if filename contains text.
• append: Append string (or list of strings) text to filename.
• confirm: Ask user a yes/no question and return their response as True /
False.
Sunday, August 29, 2010
13. Fabric Decorators
• hosts: Defines on which host or hosts to execute the wrapped
function.
• roles: Defines a list of role names, used to look up host lists.
• runs_once: Prevents wrapped function from running more than
once.
@hosts('user1@host1', 'host2', 'user2@host3')
@runs_once
def my_func():
pass
@roles('web')
def my_other_func():
pass
Sunday, August 29, 2010
14. app
fabfile
fabfile http://gist.github.com/472566
Sunday, August 29, 2010
15. Reference
Fabric documentation http://fabfile.org/
Pythonic Deployment with Fabric 0.9
Fabric: A Capistrano Alternative
Sunday, August 29, 2010