将参数传递给Capistrano [英] Passing parameters to Capistrano
问题描述
我的问题是 cap deploy
没有足够的信息来做任何事情。重要的是,它缺少我要部署的版本的标签,而这个 要在命令行中传递。
其他问题是我如何指定我的git存储库。我们的git服务器通过用户帐户的SSH进行访问,但是我不知道如何更改 deploy.rb
以将用户的id作为scm URL的一部分。 / p>
那么,我该如何完成这些呢?
示例
我想部署第一个sprint的结果第二版。这在git仓库中被标记为 r2s1
。另外,假设用户johndoe获得部署系统的任务。要访问存储库,他必须使用URL johndoe@gitsrv.domain:app
。因此,存储库的远程URL取决于用户ID。
获取所需文件的命令行将是:
git clone johndoe@gitsrv.domain:app
cd app
git checkout r2s1
has jarrad表示,capistrano-ash是部署其他项目类型的一个很好的基本帮助模块,虽然不是在一天结束时需要。它只是一种脚本语言,大多数任务都是使用系统命令完成的,最终变成几乎像shell脚本一样。
要传入参数,可以设置-s标志当运行帽子给你一个键值对。首先创建一个这样的任务。
desc参数测试
task:parameter do
puts参数测试#{branch}#{tag}
end
然后开始你的任务所以
cap test:parameter -s branch = master -s tag = 1.0.0
最后一部分。我建议使用ssh密钥设置无密码访问到您的服务器。但如果您想从当前登录的用户那里获取它。你可以这样做。
desc参数测试
task:parameter do
system whoami,user)
puts参数测试#{user}#{branch}#{tag}
end
更新:已编辑以使用最新版本的Capistrano。配置数组不再可用。
全局参数:查看注释使用set:branch,fetch(:branch,'a-default-值')来全局使用参数。 (并且用-S代替它们。)
I'm looking into the possibility of using Capistrano as a generic deploy solution. By "generic", I mean not-rails. I'm not happy with the quality of the documentation I'm finding, though, granted, I'm not looking at the ones that presume you are deploying rails. So I'll just try to hack up something based on a few examples, but there are a couple of problems I'm facing right from the start.
My problem is that cap deploy
doesn't have enough information to do anything. Importantly, it is missing the tag for the version I want to deploy, and this has to be passed on the command line.
The other problem is how I specify my git repository. Our git server is accessed by SSH on the user's account, but I don't know how to change deploy.rb
to use the user's id as part of the scm URL.
So, how do I accomplish these things?
Example
I want to deploy the result of the first sprint of the second release. That's tagged in the git repository as r2s1
. Also, let's say user "johndoe" gets the task of deploying the system. To access the repository, he has to use the URL johndoe@gitsrv.domain:app
. So the remote URL for the repository depends on the user id.
The command lines to get the desired files would be these:
git clone johndoe@gitsrv.domain:app
cd app
git checkout r2s1
Has jarrad has said, capistrano-ash is a good basic set of helper modules to deploy other project types, though it's not required as at the end of the day. It's just a scripting language and most tasks are done with the system commands and end up becoming almost shell script like.
To pass in parameters, you can set the -s flag when running cap to give you a key value pair. First create a task like this.
desc "Parameter Testing"
task :parameter do
puts "Parameter test #{branch} #{tag}"
end
Then start your task like so.
cap test:parameter -s branch=master -s tag=1.0.0
For the last part. I would recommend setting up passwordless access using ssh keys to your server. But if you want to take it from the current logged in user. You can do something like this.
desc "Parameter Testing"
task :parameter do
system("whoami", user)
puts "Parameter test #{user} #{branch} #{tag}"
end
UPDATE: Edited to work with the latest versions of Capistrano. The configuration array is no longer available.
Global Parameters: See comments Use set :branch, fetch(:branch, 'a-default-value') to use parameters globally. (And pass them with -S instead.)
这篇关于将参数传递给Capistrano的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!