[英]Is it possible to run fabfile as global script
I wrote a fabfile for our developers this week to help with deployment of DBs and files to remote staging and production environments. 我本周为开发人员编写了一个fabfile,以帮助将DB和文件部署到远程登台和生产环境。 Its a fairly complex fabfile that uses configured json file to help set production / staging env variables.
它是一个相当复杂的fabfile,它使用配置的json文件来帮助设置生产/暂存环境变量。
My question is can I somehow add my fabfile to /usr/bin to run the fabfile globally. 我的问题是我可以以某种方式将我的fabfile添加到/ usr / bin以全局运行fabfile。 Being able to run commands without having to copy and past the fabfile into each webroot(design agency problems).
能够运行命令而不必将fabfile复制并粘贴到每个webroot(设计代理问题)。
Ideally i could do: 理想情况下,我可以做到:
fab deploy
within Sites/site.dev/ or Sites/site2.dev/ without having to copy the fabfile into those directories. 在Sites / site.dev /或Sites / site2.dev /中,而无需将fabfile复制到这些目录中。 I assume there must be a way to accomplish this using aliases but my knowledge here is too weak to get that job done.
我认为必须有一种使用别名完成此操作的方法,但是我的知识太薄弱,无法完成这项工作。
My system is osx. 我的系统是osx。
I think I solved my dilemma. 我想我解决了困境。 It turns out you can specify fabfile location using the -f flag.
事实证明,您可以使用-f标志指定fabfile位置。 from here it was pretty simple to create aliases for commands like
从这里开始,为诸如以下命令创建别名非常简单
alias deployfiles='fab -f ../devops/fabfile.py syncfiles'
$ deployfiles
Pretty obvious, surprised no one gave this solution. 很明显,没有人给这个解决方案感到惊讶。
On Mac, another option is just add the following to the top of your fab file: 在Mac上,另一种选择是将以下内容添加到fab文件的顶部:
#!/usr/bin/env fab -f
def boo():
print 'x'
Then you can run it like so: 然后,您可以像这样运行它:
(venv)machine:soft kane$ ./test.py -l
Available commands:
boo
(venv)machine:soft kane$ ./test.py boo
x
Done.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.