Fabric简介
Fabric是一个Python库,为应用程序的自动部署,无缝集成了SSH。Fabric is a Python (2.5-2.7) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.It provides a basic suite of operations for executing local or remote shell commands (normally or via sudo) and uploading/downloading files, as well as auxiliary functionality such as prompting the running user for input, or aborting execution.
安装Fabric
在Ubuntu 16.04上,使用如下命令安装fabric:
1 | sudo pip install fabric |
使用Fabric
Fabric常用接口
在使用Fabric之前,有必要了解Fabric常用接口:
1 | run (fabric.operations.run) |
如下是一段简单的Python部署示例脚本:
1 | from fabric.api import * |
脚本编辑完成后,只需要在Jenkins中执行即可自动化部署:
1 | python /home/hl/devops/jenkins-local/backend/credit-system/deploy.py |