简体   繁体   English

Bundler + RVM + Passenger + Capistrano部署和缺少的宝石

[英]Bundler + RVM + Passenger + Capistrano deployment & missing gems

I got the server with the configuration above. 我得到了上面配置的服务器。

This is the important part of my deploy.rb recipe: 这是我的deploy.rb配方的重要部分:

$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
require 'bundler/capistrano'

set :rvm_ruby_string, 'ruby-1.9.2-p290'
set :rvm_type, :system
set :bundle_flags, "--deployment"

set :default_environment, {
  'PATH' => ENV['PATH'],
  'RAILS_ENV' => ENV['RAILS_ENV']
}

set :stages, %w(staging production)
require 'capistrano/ext/multistage'

Running cap staging deploy as is, leads to an error: 按原样运行cap staging deploy会导致错误:

* executing "cd /mnt/data-store/project/releases/shared &&
bundle install --gemfile /mnt/data-store/project/releases/shared/Gemfile
--path /mnt/data-store/project/shared/bundle --deployment --without development test"

** [out :: localhost] The --deployment flag requires a Gemfile.lock.
Please make sure you have checked your Gemfile.lock into version control
before deploying.

... rolling back ...

failed: "env PATH=... RAILS_ENV=staging rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell 'ruby-1.9.2-p290' -c 'cd /mnt/data-store/project/releases/shared && bundle install --gemfile /mnt/data-store/project/releases/shared/Gemfile --path /mnt/data-store/project/shared/bundle --deployment --without development test'" on localhost

Gemfile and Gemfile.lock are in the source control. Gemfile和Gemfile.lock位于源代码管理中。 I ran bundle install locally first to generate the .lock file. 我首先在本地运行bundle install以生成.lock文件。 But the bundler/capistrano points to /mnt/data-store/project/releases/shared/Gemfile so I just copied manually both files there. 但是bundler / capistrano指向/ mnt / data-store / project / releases / shared / Gemfile,所以我只是手动复制了两个文件。 I'm sure I'm doing it wrong here. 我确定我在这里做错了。 I guess it should be copied automatically. 我想它应该自动复制。

Executed deploy again (1) and it didn't fail on the bundle install, it even had 再次执行部署(1)并且它在捆绑安装上没有失败,它甚至有

Your bundle is complete! It was installed into /mnt/data-store/project/shared/bundle Your bundle is complete! It was installed into /mnt/data-store/project/shared/bundle in the output. Your bundle is complete! It was installed into /mnt/data-store/project/shared/bundle中。

BUT, one of my cap tasks executes a rake. 但是,我的一个上限任务执行一个耙子。 The result of this is: *Could not find bcrypt-ruby-3.0.1 in any of the sources *Try running bundle install . 结果是:*无法在任何源中找到bcrypt-ruby-3.0.1 *尝试运行bundle install

Proceeding with my adventure, I discovered that once you have .bundle/config with BUNDLE_PATH: /mnt/data-store/project/shared/bundle It works. 继续我的冒险,我发现一旦你有.bundle / config与BUNDLE_PATH: /mnt/data-store/project/shared/bundle它的工作原理。 I had this directory, probably created by bundler, under /mnt/data-store/releases/shared/ , so I copied manually to the rails root. 我有这个目录,可能是由bundler在/mnt/data-store/releases/shared/ ,所以我手动复制到rails根目录。

Now, rake/rails c work. 现在,rake / rails c工作。

bundle show twitter shows .../shared/bundle/ruby/1.9.1/gems/twitter-1.7.1 . bundle show twitter shows .../shared/bundle/ruby/1.9.1/gems/twitter-1.7.1

BUT, redeploying brings me back to (1), because the .bundle dir isn't there. 但是,重新部署将我带回(1),因为.bundle目录不存在。

Concrete questions: 具体问题:

  1. Do I need to create/copy .bundle/config manually? 我是否需要手动创建/复制.bundle / config?
  2. Do I need to copy Gemfile/Gemfile.lock manually to the shared dir? 我是否需要手动将Gemfile / Gemfile.lock复制到共享目录? What happens if I add gems? 如果我添加宝石怎么办? Should I hold two copies, or manually/programmatically sync them? 我应该保留两份副本,还是手动/以编程方式同步它们?
  3. WHAT AM I DOING WRONG? 我究竟做错了什么?

Thanks! 谢谢!

Look at this part in the deployment.rb file (Bundler code) 在deployment.rb文件(Bundler代码)中查看此部分

args = ["--gemfile #{File.join(context.fetch(:current_release), bundle_gemfile)}"]
args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?

There's a key called :current_release , this key is probably not being set correctly with Capistrano for some reason. 有一个名为:current_release键,由于某些原因,这个键可能没有被Capistrano正确设置。

the :current_release in bundler will point to the "shared" folder instead of the latest release (with the timestamp) :current_release bundler中的:current_release将指向“共享”文件夹而不是最新版本(带时间戳)

This is getting executed on before 'deploy:finalize_update' . 这将before 'deploy:finalize_update'执行。

What I would do in order to fix this is to add your own hook on this event. 我要做的就是在这个事件上添加你自己的钩子。

before 'deploy:finalize_update', 'x:set_current_release'

And this is the actual method 这是实际的方法

task :set_current_release, :roles => :app do
    set :current_release, latest_release
end

Error 错误

The --deployment flag requires a Gemfile.lock. Please make sure you have checked your Gemfile.lock into version control before deploying.

occurs when there is something unwantend inside your releases directory on server. 当服务器上的发行版目录中存在未解决的内容时发生。 There should be only directories with previous versions of your app (their names starts with date and looks like 20111025125442). 应该只有您的应用程序以前版本的目录(其名称以日期开头,看起来像20111025125442)。

So, remove unwanted directories or files and then try to deploy again. 因此,删除不需要的目录或文件,然后再次尝试部署。

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

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