在多个项目中共享fabfile [英] Sharing a fabfile across multiple projects
问题描述
Fabric 已经成为我部署a href =的选择的部署工具http://www.djangoproject .comrel =nofollow noreferrer> Django 项目,并初步配置Ubuntu 片。不过,我目前的工作流程与 Fabric 不是很相似的 DRY ,因为我发现自己:
Fabric has become my deployment tool of choice both for deploying Django projects and for initially configuring Ubuntu slices. However, my current workflow with Fabric isn't very DRY, as I find myself:
- 复制
fabfile.py
从一个 Django 项目到另一个 - 根据每个项目的需要修改
fabfile.py
(例如,将webserver_restart
任务更改为Apache到Nginx,配置主机和SSH端口等)。
- copying the
fabfile.py
from one Django project to another and - modifying the
fabfile.py
as needed for each project (e.g., changing thewebserver_restart
task from Apache to Nginx, configuring the host and SSH port, etc.).
此工作流的一个优点是 fabfile.py
成为我 Git 存储库的一部分,所以在 fabfile.py
和 pip requirements.txt
,我有一个可重新创建的 virtualenv 和部署过程。我想保持这个优势,同时成为更多的 DRY 。看来我可以通过以下方式改进我的工作流程:
One advantage of this workflow is that the fabfile.py
becomes part of my Git repository, so between the fabfile.py
and the pip requirements.txt
, I have a recreateable virtualenv and deployment process. I want to keep this advantage, while becoming more DRY. It seems that I could improve my workflow by:
- 能够
pip install
具有fab_config
的fabfile.py
和 - 中定义的常见任务包含每个项目的主机配置信息的文件,并根据需要覆盖任何任务
- being able to
pip install
the common tasks defined in thefabfile.py
and - having a
fab_config
file containing the host configuration information for each project and overriding any tasks as needed
Any recommendations on how to increase the DRYness of my Fabric workflow?
推荐答案
我已经在这个方面做了一些工作,包括基于类的服务器定义,包括连接信息,并可以以不同的方式覆盖方法来执行特定任务。然后我的库存fabfile.py(从不改变)只是调用服务器定义对象上的正确方法。
I've done some work in this direction with class-based "server definitions" that include connection info and can override methods to do specific tasks in a different way. Then my stock fabfile.py (which never changes) just calls the right method on the server definition object.
这篇关于在多个项目中共享fabfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!