使用capistrano从不同的git分支部署 [英] Using capistrano to deploy from different git branches

查看:86
本文介绍了使用capistrano从不同的git分支部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用capistrano来部署RoR应用程序。代码库位于git存储库中,并且在开发中广泛使用分支。 Capistrano使用 deploy.rb 文件进行设置,其中一个是要从中部署的分支。



我的问题是:假设我从 master 创建了一个新分支 A 。部署文件将引用 master 分支。我编辑它,所以可以将 A 部署到测试环境。我完成了该功能,并将分支 A 合并到 master 中。由于 A 中的 deploy.rb 文件更新,因此它将被合并,现在 deploy.rb master 分支引用 A 中。再次编辑的时间。

这是很多看似不必要的手动编辑 - 参数应该始终与当前分支名称匹配。最重要的是,很容易忘记每次编辑设置。



自动完成此过程的最佳方式是什么?



编辑:结果某人已经完成了我所需要的工作


今天早上我有机会将git存储库的一个分支部署到
a分段服务器,但是并没有想象如何。通过capistrano源代码快速搜索
,发现我可以在我的部署脚本中使用set
:branchbranch_name。我试过了,它工作。
然后我发现我需要对所有
分行进行类似的更改。当然,我是一个懒惰的草皮,并想知道如果没有
更好的方法。



如果你不熟悉git,输出的git分支命令
是一个带有星号的分支的列表,表示当前计算机上已签出
。例如:

 > git branch 
* drupal_authentication
fragment_caching
master

所以,我想象一下,如果我只是解析了输出并搜索了标记为current的
分支,那该怎么办呢?

  set:branch, $ git branch` =〜/ \ *(\S +)\s / m 

现在,我可以从单个共享的部署脚本部署当前机器上的任何分支




将此行添加到config / deploy.rb中:

  set:branch,ENV ['BRANCH'] if ENV ['BRANCH'] 

然后调用capistrano:

  cap production deploy BRANCH = master 

该解决方案适用于Capistrano< 3.1

  #call with cap -s env =< env>分支= LT; BRANCHNAME> 中部署

set:分支,fetch(:branch,master)
set:env,fetch(:env,production)


I am using capistrano to deploy a RoR application. The codebase is in a git repository, and branching is widely used in development. Capistrano uses deploy.rb file for it's settings, one of them being the branch to deploy from.

My problem is this: let's say I create a new branch A from master. The deploy file will reference master branch. I edit that, so A can be deployed to test environment. I finish working on the feature, and merge branch A into master. Since the deploy.rb file from A is fresher, it gets merged in and now the deploy.rb in master branch references A. Time to edit again.

That's a lot of seemingly unnecessary manual editing - the parameter should always match current branch name. On top of that, it is easy to forget to edit the settings each and every time.

What would be the best way to automate this process?

Edit: Turns out someone already had done exactly what I needed:

This morning I had occasion to deploy a branch of a git repository to a staging server but hadn’t the foggiest idea how. A quick search through the capistrano source code revealed that I could use set :branch "branch_name" in my deploy script. I tried it and it worked. I then figured I would need to make a similar change across all my branches. Of course, I’m a lazy sod and wondered if there wasn’t a better way.

If you’re not familiar with git, the output of the git branch command is a list of branches with an asterisk marking the one currently checked out on your local machine. For example:

> git branch
* drupal_authentication
fragment_caching
master

So, I figured, what if I just parsed the output and searched for the branch marked as current:

set :branch, $1 if `git branch` =~ /\* (\S+)\s/m

Now I’m able to deploy whatever branch is current on my local machine from a single, shared, deploy script.

解决方案

This works with Capistrano >= 3.1:

add this line to config/deploy.rb:

set :branch, ENV['BRANCH'] if ENV['BRANCH']

and then call capistrano with:

cap production deploy BRANCH=master

This solution works with Capistrano < 3.1:

#call with cap -s env="<env>" branch="<branchname>" deploy

set :branch, fetch(:branch, "master")
set :env, fetch(:env, "production")

这篇关于使用capistrano从不同的git分支部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆