简体   繁体   English

Capistrano配置

[英]Capistrano configuration

I'm having some issues with variable scope with the capistrano-ext gem's multistage module. 我在capistrano-ext gem的多阶段模块的可变范围方面遇到一些问题。 I currently have, in config/deploy/staging.rb . 我目前在config/deploy/staging.rb

set(:settings) { YAML.load_file("config/deploy.yml")['staging'] }

set :repository,  settings["repository"]
set :deploy_to,   settings["deploy_to"]
set :branch,      settings["branch"]
set :domain,      settings["domain"]
set :user,        settings["user"]

role :app, domain
role :web, domain
role :db,  domain, :primary => true

My config/deploy/production.rb file is similar. 我的config/deploy/production.rb文件是相似的。 This doesn't seem very DRY. 这似乎不是很干。 Ideally, I think I'd like everything to be in the deploy.rb file. 理想情况下,我想我希望所有内容都在deploy.rb文件中。 If there were a variable set with the current stage, everything would be really clean. 如果当前阶段有一个变量集,那么一切都会很干净。

UPDATE: I found a solution. 更新:我找到了解决方案。

I defined this function in deploy.rb : 我在deploy.rb定义了此功能:

def set_settings(params)
  params.each_pair do |k,v|
    set k.to_sym, v
  end
  if exists? :domain
    role :app, domain
    role :web, domain
    role :db,  domain, :primary => true
  end
end

Then my staging.rb file is just set_settings(YAML.load_file("config/deploy.yml")['staging']) 然后我staging.rb文件只是set_settings(YAML.load_file("config/deploy.yml")['staging'])

You're making this overly complicated. 您使这个变得过于复杂。

Just put your common code into your deploy.rb file: 只需将您的通用代码放入您的deploy.rb文件中:

role :app, domain
role :web, domain
role :db,  domain, :primary => true

and your stage-dependent settings in your config/deploy/staging.rb, production.rb, etc. files. 以及config / deploy / staging.rb,production.rb等文件中与阶段有关的设置。

Then run cap deploy, like you said: cap staging deploy 然后运行cap deploy,如您所说:cap临时部署

Your stage.rb files can use common variables as well. 您的stage.rb文件也可以使用公共变量。 For example, my staging file just has one line: 例如,我的登台文件只有一行:

set :deploy_to, "/var/www/#{domain}_staging" 设置:deploy_to,“ / var / www /#{domain} _staging”

The rest is in deploy.rb 其余的在deploy.rb中

Eli, 以利

Yes you can do cap staging deploy. 是的,您可以进行上限分段部署。 Do this at the top of your deploy file. 在部署文件的顶部执行此操作。

set :deploy_env,  ARGV[0].to_sym

or without the symbol if you prefer. 或者如果您愿意,也可以不带符号。 But note that this might mandate an environment for simple things like running 但是请注意,这可能要求为运行简单的事物提供环境

cap -vT

尝试CAPDEV='staging' cap deployENV['CAPDEV']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM