Ruby on rails 个人服务器上类似heroku的工作流
我正在尝试使用类似于的纯git工作流设置服务器。我不需要帮助设置git,但出于提供信息的目的,我正在使用。我想(以某种方式)在这个系统的操作系统(Ubuntu)中编写自定义钩子,这样,当它接收到一个特定分支上的推送时,它就会执行heroku所做的所有操作(启动Rack、Mongrel、Apache(在我的例子中是静态服务页面)等等) 有人能给我指点一个资源来做这件事吗?或者至少开始吧?谷歌搜索似乎没有什么帮助…你看过了吗?来自维基: Capistrano是一个实用工具和框架 用于在上并行执行命令 多个远程机器,通过SSH.It 使用简单的特定于域的语言 部分借用工具耙。 Rake类似于C世界中的make 并允许您定义任务 在某些情况下可应用于机器 角色。它还支持隧道 通过某台网关计算机进行连接 允许执行操作 在VPN和防火墙后面 卡皮斯特拉诺 最初是为了简化 并自动部署web服务 分布式应用 环境,最初是 与一组设计的任务捆绑在一起 用于部署Rails应用程序 部署任务现在(截至) Capistrano 2.0)选择加入并要求 客户端显式地放入“加载” 在他们的食谱中“部署” 它不是基于任何类型的提交或发布挂钩,尽管我确信如果您真的需要它,那么您将能够找到一些示例食谱来做类似的事情 更新:也许(基于Capistrano)是您想要的: 在远程存储库上安装有用的git钩子的工具,以便在主机上实现基于推送的类似Heroku的部署Ruby on rails 个人服务器上类似heroku的工作流,ruby-on-rails,git,ubuntu,workflow,heroku,Ruby On Rails,Git,Ubuntu,Workflow,Heroku,我正在尝试使用类似于的纯git工作流设置服务器。我不需要帮助设置git,但出于提供信息的目的,我正在使用。我想(以某种方式)在这个系统的操作系统(Ubuntu)中编写自定义钩子,这样,当它接收到一个特定分支上的推送时,它就会执行heroku所做的所有操作(启动Rack、Mongrel、Apache(在我的例子中是静态服务页面)等等) 有人能给我指点一个资源来做这件事吗?或者至少开始吧?谷歌搜索似乎没有什么帮助…你看过了吗?来自维基: Capistrano是一个实用工具和框架 用于在上并行执行命令
听起来你想在Git工作流中的某个特定点执行任意功能,Git钩子是一个不错的选择 如果您查看任何Git回购(在
.Git
文件夹中),您将看到一个hooks
文件夹。其中有许多具有不同名称的示例hook文件。根据上面的解释,您希望编辑post receive
hook文件,因为在远程repo中更新新的ref后(由本地repo推送而来)将立即调用该文件.如需更多信息,请阅读或阅读此内容
你可以把你想要的任何shell命令放在一个钩子文件中。将文件名从
post-receive.sample
更改为简单的post-receive
,添加启动Rack、Mongrel、Apache等所需的命令,然后用一个快速的chmod+x-post-receive
使文件可执行,一切就绪。e在git push上使用capistrano将主分支自动部署为暂存。从生产分支手动部署生产
安装程序要求您使用deploy.rb
中的set:deploy\u via,:remote\u cache
在服务器上具有本地缓存副本。如果自上次部署以来已更改,则可以使用最新配置运行capistrano
post-receive
hook脚本:
#!/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
#!/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
不使用:远程\u缓存
的简单设置也是可能的,但它将使用以前的(当前部署的)配置运行capistrano,并且seams将更加脆弱
post-receive
hook脚本:
#!/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
#!/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
我刚刚发现了这一点,这正是我想要的。我将另一个答案保留为“正确”(因为它是当时最好的),但我现在使用的是git deploy:)我建议签出,它基于技术,非常易于安装和使用
如果你也在寻找云提供商,我推荐,因为他们支持开箱即用的Dokku!查看他们的帐户以获取更多信息
您的工作流程将非常类似于Heroku:()
Git Remote添加myherokudokku@DOMAIN.com:您的应用程序
git推送myheroku主机
http://your-app.DOMAIN.com
dokku域:设置你的应用程序NEWDOMAIN.com
值得一提的是,新项目名为Dokku,它比Dokku具有更多的功能。阅读Flynn和Dokku背后的历史,这完全不相干。我不需要知道如何部署应用程序,我需要知道如何使用自定义挂钩在通过Git推送应用程序时自动启动这些进程。您可以在Capistrano中创建任务来控制应用程序服务器的启动和停止。所以不,不是完全不相关。是的,但我也可以用简单的rake甚至bash脚本来实现这一点。@seth想要什么,@galador提供什么,唯一的区别是@seth只想从他的开发盒中使用git。这就是我的“更新”链接的工作方式(git deploy)。您只需运行一次安装程序即可进行初始化,然后可以执行类似于“git push origin production”(git push origin production)的操作(
production
是您希望自动部署的任何分支)。然后,它在服务器端使用可爱的git钩子自动执行部署操作(哪些操作由代码中发生的更改决定,并在github页面的“部署”部分详细描述)。谢谢,这正是我需要的!我有点不高兴我的答案没有被选中,因为更新的版本包含了一个指向git deploy的链接,它完全符合作者的要求(“纯git工作流类似于Heroku”——并在评论中解释了它是如何工作的),但我也会给你一个投票。