在多个项目*享fabfile

在多个项目*享fabfile

问题描述:

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:


  1. 复制 fabfile.py 从一个 Django 项目到另一个

  2. 根据每个项目的需要修改 fabfile.py (例如,将 webserver_restart 任务更改为Apache到Nginx,配置主机和SSH端口等)。

  1. copying the fabfile.py from one Django project to another and
  2. modifying the fabfile.py as needed for each project (e.g., changing the webserver_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:


  1. 能够 pip install 具有 fab_config fabfile.py

  2. 中定义的常见任务包含每个项目的主机配置信息的文件,并根据需要覆盖任何任务

  1. being able to pip install the common tasks defined in the fabfile.py and
  2. having a fab_config file containing the host configuration information for each project and overriding any tasks as needed

有关如何增加 DRY 我的面料工作流程?

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.