Capistrano Multistage deploying to wrong directory

2020-02-23 07:25发布

Im having some problems with my capistrano setup after updating my gems lately. I have a multistage setup with a production and staging setup.

/config/deploy.rb

# setup multistage
set :stages, %w(testing production)
set :default_stage, "testing"
require 'capistrano/ext/multistage'

/config/deploy/production.rb

# Set deploy path
set :deploy_to, "/var/www/mysite/live"
set :rails_env, "production"

/config/deploy/testing.rb

# Set deploy path
set :deploy_to, "/var/www/mysite/test"
set :rails_env, "test"

Problem is that it seems to ignore my deploy_to setting. It just deploys to the default /u/apps/mysite.

I don't know if it has any relevance, the cause of all of this is a move from apache+passenger to nginx+unicorn. I don't think it has anything to do with that though, as this is just the checkout process.

4条回答
来,给爷笑一个
2楼-- · 2020-02-23 07:34

I stumbled across this while on Stack Overflow. Its an old question but since its flagged as open I'm going to give it a shot.

I think this might be a scope issue with how the Capistrano Instances get loaded.

I notice this syntax doesn't work in the production.rb and test.rb files

 set :deploy_to, "/var/www/mysite/live"

But this one does:

set(:deploy_to)  { "/var/www/#{application}/live" }

Its a subtle difference but I think the one that works is actually passing the information as a Proc block, whereas the first one is passing it as a string. I have a sneaky suspicion that by the time the Capistrano Instance comes into being that string is no longer present.

This would indicate to me that something is off in your load or require order as you should be able to set the deploy variables in these files. If you can't figure it out you may be able to cheat and surround the deploy/production.rb or deploy/test.rb code with

Capistrano::Configuration.instance.load do
  # variables, etc here
end

That would definitely tell you that this file isn't being loaded within the scope of the Capistrano instance.

Also minor point but the files should be in

config/deploy # relative to your Rails app

Not

/config/deploy/ # this is an absolute path off of your root folder

Good Luck. Hopefully you've already solved this issue!

查看更多
姐就是有狂的资本
3楼-- · 2020-02-23 07:36

Could be just the order you have it in your deploy.rb? put the require above the stage settings

require 'capistrano/ext/multistage'

# setup multistage
set :stages, %w(testing production)
set :default_stage, "testing"
查看更多
▲ chillily
4楼-- · 2020-02-23 07:38

I eventually solved this by adding the following to my deploy/production.rb and testing.rb

set(:deploy_to)         { "/var/www/#{application}/live" }
set(:releases_path)     { File.join(deploy_to, version_dir) }
set(:shared_path)       { File.join(deploy_to, shared_dir) }
set(:current_path)      { File.join(deploy_to, current_dir) }
set(:release_path)      { File.join(releases_path, release_name) }
查看更多
smile是对你的礼貌
5楼-- · 2020-02-23 07:41

Where are those production.rb and testing.rb located in the project?

Make sure they are under config/deploy.

查看更多
登录 后发表回答