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/

  • 相关阅读:
    Docker基础技术-Linux Namespace
    基于 Kata Containers 与 iSulad 的云容器实践解析
    runc network
    cgroup--device systemd-cgls + devices.deny
    setcap capabilities cap_net_raw
    kata agent
    什么是路演
    穿行测试
    交易性金融资产与可供出售金融资产
    什么情况使用消极式函证
  • 原文地址:https://www.cnblogs.com/maplye/p/5351022.html
Copyright © 2011-2022 走看看