个人服务器上类似heroku的工作流程

发布于 2024-10-14 05:38:47 字数 335 浏览 3 评论 0原文

我正在尝试使用类似于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

游魂 2024-10-21 05:38:47

听起来您想在 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 a hooks folder. Inside it there are a number of example hook files with different names. Based on your explanation above, you want to edit the post-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 simply post-receive, add the commands you need to start Rack, Mongrel, Apache, etc., then make the file executable with a quick chmod +x post-receive and you're all set.

凉栀 2024-10-21 05:38:47

您看过 Capistrano 吗?来自维基:

Capistrano 是一个实用程序和框架
用于并行执行命令
通过 SSH 多台远程计算机。它
使用简单的领域特定语言
部分借自工具耙。
Rake类似于C世界中的make
并允许您定义任务,其中
可以应用于某些机器
角色。它还支持隧道
通过某些网关机器的连接
允许执行操作
在 VPN 和防火墙后面。

卡皮斯特拉诺
最初是为了简化
并自动化部署网络
应用到分布式
环境,最初来
与一组设计的任务捆绑在一起
用于部署 Rails 应用程序。这
部署任务现在(截至
Capistrano 2.0) 选择加入并要求
客户端明确放置“负载
“部署””在他们的食谱中。

它不是基于任何类型的提交或后挂钩,尽管我确信如果您真的需要它,那么您将能够找到一些示例食谱来执行类似的操作。

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

一个在远程存储库上安装有用的 git hook 的工具,以在主机上启用基于推送、类似 Heroku 的部署。

Have you looked at Capistrano? From wiki:

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.

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:

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

﹏半生如梦愿梦如真 2024-10-21 05:38:47

我刚刚发现 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 :)

青丝拂面 2024-10-21 05:38:47

我有一个类似的设置,其中主分支使用 git Push 上的 capistrano 自动部署为临时分支。生产是从生产分支手动部署的。

该设置要求您在 deploy.rb 中使用 set :deploy_via, :remote_cache 以在服务器上拥有本地缓存​​副本。这是为了能够使用最新配置运行 capistrano(如果自上次部署以来已更改)。

post-receive 钩子脚本:

#!/bin/bash
while read oldrev newrev ref
do
        if [ "$ref" = "refs/heads/master" ] ; then
                echo "Master branch pushed, deploying to staging"
                # seams to be set to "." for hooks, unset to make things more normal
                unset GIT_DIR
                # deploy path, where "current", "releases", "shared" etc are
                DEPLOYDIR="/home/user/deploy/staging"
                # default path for :deploy_via :remote_cache is shared/cached-copy
                cd "$DEPLOYDIR/shared/cached-copy"
                # update cache to pushed revision, will be done by capistrano too
                git fetch origin && git fetch --tags origin && git reset --hard "$newrev"
                # load rvm
                source ~/.rvm/scripts/rvm
                rvm use 1.9.2
                # make sure correct gems are installed
                # this will also create a .bundle directory
                bundle install --gemfile Gemfile --path "$DEPLOYDIR/shared/bundle" --deployment --without development test
                # run capistrano
                # if you use deploy:migrations instead of deploy you should probably add
                # after "deploy:migrations", "deploy:cleanup"
                # to your deploy.rb
                bundle exec cap staging deploy:migrations
        fi
done

没有 :remote_cache 的更简单的设置也是可能的,但它将使用以前的(当前部署的)配置运行 capistrano 并且接缝有点脆弱。

post-receive 钩子脚本:

#!/bin/bash
while read oldrev newrev ref
do
        if [ "$ref" = "refs/heads/master" ] ; then
                echo "Master branch pushed, deploying to staging"
                # seams to be set to "." for hooks, unset to make things more normal
                unset GIT_DIR
                source ~/.rvm/scripts/rvm
                rvm use 1.9.2
                cd /home/user/deploy/staging/current && bundle exec cap staging deploy:migrations  
        fi
done

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 in deploy.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:

#!/bin/bash
while read oldrev newrev ref
do
        if [ "$ref" = "refs/heads/master" ] ; then
                echo "Master branch pushed, deploying to staging"
                # seams to be set to "." for hooks, unset to make things more normal
                unset GIT_DIR
                # deploy path, where "current", "releases", "shared" etc are
                DEPLOYDIR="/home/user/deploy/staging"
                # default path for :deploy_via :remote_cache is shared/cached-copy
                cd "$DEPLOYDIR/shared/cached-copy"
                # update cache to pushed revision, will be done by capistrano too
                git fetch origin && git fetch --tags origin && git reset --hard "$newrev"
                # load rvm
                source ~/.rvm/scripts/rvm
                rvm use 1.9.2
                # make sure correct gems are installed
                # this will also create a .bundle directory
                bundle install --gemfile Gemfile --path "$DEPLOYDIR/shared/bundle" --deployment --without development test
                # run capistrano
                # if you use deploy:migrations instead of deploy you should probably add
                # after "deploy:migrations", "deploy:cleanup"
                # to your deploy.rb
                bundle exec cap staging deploy:migrations
        fi
done

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:

#!/bin/bash
while read oldrev newrev ref
do
        if [ "$ref" = "refs/heads/master" ] ; then
                echo "Master branch pushed, deploying to staging"
                # seams to be set to "." for hooks, unset to make things more normal
                unset GIT_DIR
                source ~/.rvm/scripts/rvm
                rvm use 1.9.2
                cd /home/user/deploy/staging/current && bundle exec cap staging deploy:migrations  
        fi
done
一张白纸 2024-10-21 05:38:47

我建议查看 GitHub:progrium/dokku,它基于 Docker 技术,非常易于设置和使用。

如果您也在寻找云提供商,我推荐 DigitalOcean,因为他们开箱即用地支持 Dokku!查看他们的社区文档了解更多信息。

您的工作流程将与 Heroku 非常相似:(完整教程

  1. 设置 Dokku 服务器(您的个人 Heroku)和您的公钥
  2. 配置您的域以将 *.DOMAIN.com 指向 Dokku 服务器
  3. 将 Git Remote 添加到您的存储库:git remote add myheroku [email protected]:your-app
  4. 将代码推送到 Dokku 服务器: git push myheroku master
  5. 签出 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)

  1. Setup Dokku Server (Your personal Heroku) and your public key
  2. Configure your domain to point *.DOMAIN.com to Dokku Server
  3. Add Git Remote to your repo: git remote add myheroku [email protected]:your-app
  4. Push code to Dokku server: git push myheroku master
  5. Checkout 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文