个人服务器上类似heroku的工作流程
我正在尝试使用类似于 heroku 的纯 git 工作流程设置服务器。我不需要设置 git 的帮助,但为了提供信息,我使用 gitolite。我想(以某种方式)在这个系统的操作系统(Ubuntu)中编写自定义钩子,这样,当它收到特定分支上的推送时,它会执行heroku所做的所有操作(启动 Rack、Mongrel、Apache(例如在我的例子中是静态服务页面)等。
有人可以向我指出一个资源来执行此操作或至少开始吗?谷歌搜索似乎并没有真正帮助......
I'm trying to set up a server with pure-git workflow similar to heroku. I don't need help setting up git, but for informative purposes, I'm using gitolite. I'd like to (somehow) write custom hooks in the operating system (Ubuntu) of this system so that, when it receives a push on a particular branch, it performs all the operators heroku does (starting Rack, Mongrel, Apache (for static serving pages in my case), etc.
Can someone point me towards a resource to do this or at least get started? A google search didn't really seem to help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
听起来您想在 Git 工作流程中的某个时刻执行任意功能。 Git hooks 是最佳选择。
如果您查看任何 Git 存储库(在
.git
文件夹内),您将看到一个hooks
文件夹。其中有许多具有不同名称的示例挂钩文件。根据上面的解释,您想要编辑post-receive
挂钩文件,因为在远程存储库中更新新引用后(由本地存储库推送而产生),该文件将立即被调用)。有关更多信息,请阅读有关钩子的官方文档或阅读更平易近人的解释。您可以将任何您想要的 shell 命令放入挂钩文件中。将文件名从
post-receive.sample
更改为简单的post-receive
,添加启动 Rack、Mongrel、Apache 等所需的命令,然后使文件可执行通过快速chmod +x post-receive
就可以了。It sounds like you want to execute arbitrary functionality at a certain point in your Git workflow. Git hooks are the way to go.
If you look in any Git repo (inside the
.git
folder), you'll see ahooks
folder. Inside it there are a number of example hook files with different names. Based on your explanation above, you want to edit thepost-receive
hook file, since that will be called immediately after a new ref has been updated in your remote repo (resulting from a push from a local one). For more info, read the official documentation on hooks or read this perhaps more approachable explanation.You can put any shell commands you want in a hook file. Change the filename from
post-receive.sample
to simplypost-receive
, add the commands you need to start Rack, Mongrel, Apache, etc., then make the file executable with a quickchmod +x post-receive
and you're all set.您看过 Capistrano 吗?来自维基:
它不是基于任何类型的提交或后挂钩,尽管我确信如果您真的需要它,那么您将能够找到一些示例食谱来执行类似的操作。
更新:也许 git-deploy (基于 Capistrano)就是你想要的:
Have you looked at Capistrano? From wiki:
It's not based on any sort of commit or post hooks, although I'm sure if you really needed that, then you would be able to find some example recipes to do something like that.
Update: Maybe git-deploy (based on Capistrano) is what you want:
我刚刚发现 https://github.com/mislav/git-deploy,这正是我想要。我将把另一个答案保留为“正确”(因为它是当时最好的),但我现在使用 git-deploy :)
I just uncovered https://github.com/mislav/git-deploy, which is EXACTLY what I wanted. I'm going to leave the other answer as "correct" (since it was the best at the time), but I'm using git-deploy now :)
我有一个类似的设置,其中主分支使用 git Push 上的 capistrano 自动部署为临时分支。生产是从生产分支手动部署的。
该设置要求您在
deploy.rb
中使用set :deploy_via, :remote_cache
以在服务器上拥有本地缓存副本。这是为了能够使用最新配置运行 capistrano(如果自上次部署以来已更改)。post-receive
钩子脚本:没有
:remote_cache
的更简单的设置也是可能的,但它将使用以前的(当前部署的)配置运行 capistrano 并且接缝有点脆弱。post-receive
钩子脚本:I have a similar setup where the master branch is automatically deployed as staging using capistrano on git push. Production is manually deployed from the production branch.
The setup require that you use
set :deploy_via, :remote_cache
indeploy.rb
to have a local cache copy on the server. This is to be able to run capistrano with the latest configuration if is has been changed since last deploy.post-receive
hook script:A simpler setup without
:remote_cache
is also possible but it will run capistrano with the previous (currently deployed) configuration and seams to be a bit more fragile.post-receive
hook script:我建议查看 GitHub:progrium/dokku,它基于 Docker 技术,非常易于设置和使用。
如果您也在寻找云提供商,我推荐 DigitalOcean,因为他们开箱即用地支持 Dokku!查看他们的社区文档了解更多信息。
您的工作流程将与 Heroku 非常相似:(完整教程)
git remote add myheroku [email protected]:your-app
git push myheroku master
http://your-app.DOMAIN.com
此外,如果您想为您的应用程序分配不同的子域或完整域,您可以安装Dokku 域插件 并简单地为您的应用指定域:
dokku 域:设置您的应用程序 NEWDOMAIN.com
值得一提的是名为 Flynn GitHub:flynn/flynn 比 Dokku 具有更多功能。 在这里阅读 Flynn 和 Dokku 背后的历史。 ..
I recommend checking out GitHub:progrium/dokku, it's based on Docker technology and really easy to setup and use.
If you're also looking for cloud provider, I recommend DigitalOcean since they support Dokku out of the box! Checkout their community documentation for more information.
Your workflow will be very much similar to Heroku: (Full Tutorial)
git remote add myheroku [email protected]:your-app
git push myheroku master
http://your-app.DOMAIN.com
Also if you want to have different sub-domain or full-domain assign to your app, you can install Dokku Domain Plugin and simply do specify domain to your-app:
dokku domains:set your-app NEWDOMAIN.com
It's worth mentioning new project called Flynn GitHub: flynn/flynn which comes with more features than Dokku. Read history behind Flynn and Dokku here...