Capistrano Configuration

I'm having problems with a variable scope with a multi-stage capistrano-ext gem module. I currently have 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. It does not seem very dry. Ideally, I would like everything to be in the deploy.rb file. If there was a variable with the current stage, everything would be really clean.

UPDATE: I found a solution.

I defined this function in 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 staging.rb just set_settings(YAML.load_file("config/deploy.yml")['staging'])

+4
source share
3 answers

You make it too complicated.

Just put your generic code in the deploy.rb file:

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

and your stage settings in config / deploy / staging.rb, production.rb, etc.

Then run command line deployment, as you said: command line deployment

Stage.rb files can also use shared variables. For example, my intermediate file has only one line:

set: deploy_to, "/ var / www / # {domain} _staging"

The rest is in deploy.rb

+2
source

try CAPDEV='staging' cap deploy and ENV['CAPDEV'] in deploy.rb

0
source

Eli,

Yes, you can perform a command line deployment. Do this at the top of your deployment file.

 set :deploy_env, ARGV[0].to_sym 

or without a character if you prefer. But keep in mind that this may indicate an environment for simple things like running

 cap -vT 
0
source

Source: https://habr.com/ru/post/1299992/


All Articles