当前位置: 首页>>技术教程>>正文


个人服务器上的heroku-like工作流程

, , , ,

问题描述

我正在尝试使用类似于heroku的pure-git工作流设置服务器。我不需要设置git的帮助,但出于提供信息的目的,我正在使用gitolite。我想(以某种方式)在该系统的操作系统(Ubuntu)中编写自定义钩子,这样,当它收到对特定分支的推送时,它将执行heroku所做的所有操作(启动Rack,Mongrel,Apache(用于在我的情况下为静态服务页面)等

有人可以指出我要这样做的资源还是至少开始使用?谷歌搜索似乎并没有真正帮助…

最佳办法

听起来您想在Git工作流程中的某个时刻执行任意功能。使用Git钩子是可行的方法。

如果您查看任何Git存储库(在.git文件夹内),您会看到一个hooks文件夹。它内部有许多示例钩子文件,它们具有不同的名称。根据上面的解释,您想编辑post-receive挂钩文件,因为在远程仓库中更新了新的引用之后(由于本地的推送而导致),该挂钩文件将立即被调用。有关更多信息,请阅读the official documentation on hooks或阅读也许more approachable explanation

您可以将任何所需的Shell命令放入挂钩文件中。将文件名从post-receive.sample更改为简单的post-receive,添加启动Rack,Mongrel,Apache等所需的命令,然后使用快速的chmod +x post-receive使该文件可执行,一切就绪。

次佳办法

您看过Capistrano吗?从维基:

Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH. It uses a simple Domain Specific Language borrowed in part from the tool rake. Rake is similar to make in the C world and allows you to define tasks, which may be applied to machines in certain roles. It also supports tunneling connections via some gateway machine to allow operations to be performed behind VPNs and firewalls.

Capistrano was originally designed to simplify and automate deployment of web applications to distributed environments, and originally came bundled with a set of tasks designed for deploying Rails applications. The deployment tasks are now (as of Capistrano 2.0) opt-in and require clients to explicitly put “load ‘deploy’” in their recipes.

它不基于任何类型的提交或发布挂钩,尽管我确定您是否确实需要,但是您将能够找到一些示例食谱来执行类似操作。

更新:也许git-deploy(基于Capistrano)是您想要的:

A tool to install useful git hooks on your remote repository to enable push-based, Heroku-like deployment on your host.

第三种办法

我只是发现了https://github.com/mislav/git-deploy,这正是我想要的。我将把另一个答案留为”correct”(因为这是当时最好的),但是我现在正在使用git-deploy 🙂

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/8015.html,未经允许,请勿转载。