zoukankan      html  css  js  c++  java
  • Fabric自动部署太方便了

    之前不知道有Fabric工具,每次发布程序到服务器上的时候,基本流程:本地打包程序 -> Ftp上传 -> 停服务器Apache -> 覆盖文件 -> 启动Apache, 非常繁琐。

    前几天无意发现了Fabric工具,研究了一下,现在我通过该工具发布程序只要一条指令即可:

    fab pack deploy

    具体如何实现的,请看实例,你只需要在你的程序跟目录下添加fabfile.py文件,内容参考如下:

    #!/usr/bin/env python
    
    from fabric.api import *
    
    # Configure user, private key, etc. for SFTP deployment
    env.user = 'root'
    env.hosts = ['SERVER IP']
    
    
    def pack():
        local('npm run build', capture=False)
        local('python setup.py sdist --formats=gztar', capture=False)
    
    def deploy():
        dist = local('python setup.py --fullname', capture=True).strip()
    
        # clean up
        sudo('rm -rf /tmp/towerres /tmp/towerres.tar.gz')
    
        put('dist/%s.tar.gz' % dist, '/tmp/towerres.tar.gz')
    
        # stop apache
        run('apachectl stop')
    
        # remove priouse folder
        run('rm /home/maplye/httpd/towerresource/towerres -rf')
        run('rm /home/maplye/httpd/towerresource/migrations -rf')
    
        # copy
        run('mkdir /tmp/towerres')
        with cd('/tmp/towerres'):
            run('tar zxf /tmp/towerres.tar.gz')
    
            run('cp -rf /tmp/towerres/%s/towerres /home/maplye/httpd/towerresource/' % dist)
            run('cp -rf /tmp/towerres/%s/migrations /home/maplye/httpd/towerresource/' % dist)
        
        # run
        with cd('/home/maplye/httpd/towerresource'):
            run('chown -R apache:apache towerres')
            run('python manage.py db upgrade')
    
        # start apache
        run('apachectl start')
    
        # clean up
        sudo('rm -rf /tmp/towerres /tmp/towerres.tar.gz')

      具体参照官网: http://www.fabfile.org/

      中文文档: http://fabric-docs-cn.readthedocs.org/zh_CN/latest/

  • 相关阅读:
    查看eclipse web项目中jsp编译后的servlet源文件【转】【JSP】
    综合实战--文件上传系统【JDBC&IO&Socket】
    002、使用webpack的各种loader处理文件
    001、node & webpack工程手动搭建
    000、GO之特别语法糖
    000、GO之深刻理解拷贝
    000、常见算法解析
    003、GO之并发
    002、GO之反射
    001、GO之指针转换
  • 原文地址:https://www.cnblogs.com/maplye/p/5351022.html
Copyright © 2011-2022 走看看