简体   繁体   中英

Environment specific Capefile capistrano3 rails 4.1

I have rails 4.1 app and multistage (staging, production) deployment with capistrano3.

I want to deploy it to one stage server (which use rvm) and one production server (which use ruby env)

By default everything works nice on production server, but without rvm1-capistrnao3 gem installed and included in Capefile I cannot deploy to staging.

Is there a way to require 'rvm1/capistrano3' in Capefile, only if I deploy to staging like that

cap staging deploy

Here is what I've done to fix it

I made default capistrano multistage setup, like Doug Hall said!

The tricky part is the way to include rvm1-capistrano3 in Capefile

See deepak's workaround here https://github.com/capistrano/rvm/issues/49

So instead of just require 'rvm1/capistrano3' in Capefile, do it like that

task :use_rvm do
  require 'rvm1/capistrano3'
end

task 'staging' => [:use_rvm]

When you run cap install, it creates a file called config/deploy.rb and two files in the config/deploy directory: production.rb and staging.rb. Use the config/deploy.rb file for all settings that both the production and staging servers have in common. Use the other two for the respective settings on those machines. I would require 'capistrano/rvm' in your Capfile, but only use it in the config/deploy/staging.rb file. Capistrano executes the common config/deploy.rb FIRST, then calls the proper staging.rb/production.rb file, so all set values from config/deploy.rb are available in the staging.rb/production.rb file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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