zoukankan      html  css  js  c++  java
  • fabric自动部署

    fabric自动部署 - eva - ITeye技术网站

    Fabric commands

    run - run a command on a remote host

    sudo - run a sudoed command on a remote host

    local - run a command on the local host

    get/put - copy a file from/to a remote host

    prompt - ask the user for information*

     

    Execute commands

    get output and return code

    output = run("command")

     

    chain commands

    run("workon project && git pull origin master")

     

    start pseudo-daemons

    run("screen -d -m not-a-daemon")

     

    any return code except() is treated as an error and an exception is

    thrown(unless warn_only is set)

     

    Move files

    Put a file(upload)

    put("local-file", "remote-file", mode=0755)

     

    Get a file(download):

    get("remote-file", "local-file")

     

    if a problem occurs while uploading or downloading files, fabric throws an exception

     

    Ask questions

    Validation

    relase_name = prompt("What do you want to name the new release?: ", validate="^[a-zA-Z0-9] + $")

    proxy_port_number = prompt("Proxy port: ", validate=int)

     

    Default

    username = prompt("Username: ", default="jack")

     

    Keeping state(sort of)

    Directories

    with cd("xmpp/"):

     run("git clone git://git/something.git")

     run("mkvirtualenv --no-site-packages somthing")

     

    For those running from trunk 

    with prefix("workon something"):

     run("pip install xx>=1.1")

     

    Contrib

    Append text to files

    from fabric.contrib.files import append

    append(" DATABASE_NAME = 'hello.db' ", "local_settings.py")

     

    Search and replace

    Use fabric's sed function to modify content of files

    from fabric.contrib.files import sed

    sed("local_settings.py", "^DEBUG = True$", "DEBUG = False")

     

    Fabric decorators

    hosts 定义那些host或hosts可以执行

    roles 定义一个角色名称的list,用于查看host lists

    runs_once 确保方法只运行一次

    Example

    from fabric.api import run

    env.hosts = [localhost]

    env.user = 'djangodev'

     

    def install_django():

     run('workon myproject && pip install diango')

     

    $fab install_django

     

    ps:

    rails的自动部署框架Capistrano

    http://gist.github.com/472566

    1. 修正bugs和实现新的特征

    2. git存档

    3. 把文件从开发环境分期移到生产环境

    4. 安装更新,重复使用apps,pypi,packages

    5. 运行备份

    6. 保持跟踪本地设置

    7. 清空和预热缓存

    8. 迁移数据库

     

    推荐

    http://www.slideshare.net/

    分享到:

  • 相关阅读:
    eclipse中解决update maven之后jre被改成1.5的问题
    Navicat for MySQL密鈅
    静态创建和动态创建对象的区别
    vector相关操作总结
    C++的编码技巧相关总结
    关于VS中未经处理的异常的梳理
    头文件用于声明而不是定义
    SQL单表查询练习部分总结
    delete对象时会自动调用类的析构函数
    SQL中的sum在何时会返回为null
  • 原文地址:https://www.cnblogs.com/lexus/p/2361945.html
Copyright © 2011-2022 走看看