简体   繁体   English

Capistrano多级部署到错误的目录

[英]Capistrano Multistage deploying to wrong directory

Im having some problems with my capistrano setup after updating my gems lately. 我最近更新了我的宝石后,我的capistrano设置有一些问题。 I have a multistage setup with a production and staging setup. 我有一个多阶段设置,包括生产和分段设置。

/config/deploy.rb /config/deploy.rb

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

/config/deploy/production.rb /config/deploy/production.rb

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

/config/deploy/testing.rb /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. 问题是它似乎忽略了我的deploy_to设置。 It just deploys to the default /u/apps/mysite. 它只是部署到默认的/ 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. 我不知道它是否有任何相关性,所有这一切的原因都是从apache + passenger到nginx + unicorn的转变。 I don't think it has anything to do with that though, as this is just the checkout process. 我不认为它与此有任何关系,因为这只是结帐过程。

I stumbled across this while on Stack Overflow. 在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. 我认为这可能是Capistrano实例如何加载的范围问题。

I notice this syntax doesn't work in the production.rb and test.rb files 我注意到这个语法在production.rb和test.rb文件中不起作用

 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. 它有一个微妙的区别,但我认为有效的实际上是将信息作为Proc块传递,而第一个将它作为字符串传递。 I have a sneaky suspicion that by the time the Capistrano Instance comes into being that string is no longer present. 我有一种偷偷摸摸的怀疑,当Capistrano实例出现时,弦不再存在。

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 如果您无法弄清楚,您可能会欺骗并围绕deploy / production.rbdeploy / test.rb代码

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. 那肯定会告诉你这个文件没有被加载到Capistrano实例的范围内。

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! 希望你已经解决了这个问题!

I eventually solved this by adding the following to my deploy/production.rb and testing.rb 我最终通过在deploy / production.rb和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) }

Where are those production.rb and testing.rb located in the project? 那些production.rb和testing.rb位于项目中的哪个位置?

Make sure they are under config/deploy . 确保它们在config/deploy

Could be just the order you have it in your deploy.rb ? 可能只是你在deploy.rb中的订单 put the require above the stage settings 将要求置于舞台设置之上

require 'capistrano/ext/multistage'

# setup multistage
set :stages, %w(testing production)
set :default_stage, "testing"

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

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