0

我已经在本地机器上成功使用 Fabric 有一段时间了,终于有了一个不错的部署脚本,我想在 git 的 post-receive 挂钩期间调用它。为了做到这一点,我有以下代码,所有这些都在fab命令之前得到验证:

deploy=... # CODE TO DETERMINE IF YOU SHOULD DEPLOY

if [[ $deploy ]] ; then
  TMPFILE="/tmp/$(basename $0).$$.tmp"
  git cat-file blob release:fabfile.py > $TMPFILE
  fab -f $TMPFILE deploy:servername.mycompany.com
  rm $TMPFILE
fi

我已经检查了每一步,我确信 TMPFILE 被正确创建(它包含我的 fabfile)。在 /tmp/ 中手动运行上面的步骤和一个组成的文件会导致相同的行为。

最糟糕的是,它“提醒”我可以-f用来指定一个 fabfile ......我就是这样。

4

1 回答 1

1

这是因为它想要一个以 .py 结尾的文件。更改您的临时文件以使用此文件扩展名,它将起作用。这是 fab 最有可能希望允许人们使用 python 样式的目录类的工件,就像fabfile/__init__.py使用-f fabfile

此行为的示例如下:

╭─mgoose@Macintosh  ~
╰─$ fab -f tmp.py test
[localhost] local: whoami
mgoose

Done.
╭─mgoose@Macintosh  ~
╰─$ mv tmp.py tmp.py.tmp
╭─mgoose@Macintosh  ~
╰─$ fab -f tmp.py.tmp test

Fatal error: Couldn't find any fabfiles!

Remember that -f can be used to specify fabfile path, and use -h for help.

Aborting.
╭─mgoose@Macintosh  ~
╰─$ cat tmp.py.tmp                                                                                                                                                                                                                        1 ↵
from fabric.api import local, task

@task
def test():
    local("whoami")
于 2013-08-01T05:37:07.640 回答