我试图在我的结构脚本中宣布部署开始和结束。感觉这应该很容易,但对于我来说,我不知道该怎么做。
env.hosts = ['www1', 'www2', 'www3', 'www4']
def announce_start():
# code to connect to irc server and announce deployment begins
pass
def announce_finish():
# code to connect to irc server and announce deployment finishes
pass
def deploy():
# actual deployment code here
pass
这是我尝试过的:
如果我使部署任务包含“announce_start”和“announce_finish”。它将尝试在每台服务器上运行所有这些任务。
def deploy():
announce_start()
# actual deployment code here
announce_finish()
如果我用@hosts('localhost')装饰announce_start()和announce_end(),它会在本地主机上运行它,但仍然是四次。每个主机一个。
当我输入此内容时,我终于通过在announce_start/end 上使用装饰器 @hosts('localhost') 和 fab 命令使其工作:
fab announce_start deploy announce_end
但这似乎有点老套。我希望将其全部包含在一个部署命令中。有没有办法做到这一点?
您可以使用fabric.api.execute,例如
def announce_start():
# code to connect to irc server and announce deployment begins
pass
def announce_finish():
# code to connect to irc server and announce deployment finishes
pass
@hosts(...)
def deploy_machine1():
pass
@hosts(...)
def deploy_machine2():
pass
def deploy():
announce_start()
execute(deploy_machine1)
execute(deploy_machine2)
announce_finish()
然后调用 fab 部署
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)