捆绑器 + RVM +乘客 + Capistrano 部署与部署缺少宝石
我得到了具有上述配置的服务器。
这是我的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'
按原样运行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和Gemfile.lock位于源代码管理中。我首先在本地运行 bundle install
来生成 .lock 文件。但是bundler/capistrano指向/mnt/data-store/project/releases/shared/Gemfile,所以我只是手动复制了这两个文件。我确信我在这里做错了。我想它应该会自动复制。
再次执行部署 (1),捆绑包安装并没有失败,甚至还有
您的捆绑包已完成!它被安装到输出中的 /mnt/data-store/project/shared/bundle
中。
但是,我的一项上限任务执行了耙子。结果是: *在任何来源中都找不到 bcrypt-ruby-3.0.1 *尝试运行bundle install
。
继续我的冒险,我发现一旦你有了 .bundle/config BUNDLE_PATH:/mnt/data-store/project/shared/bundle
有用。 我在 /mnt/data-store/releases/shared/
下有这个目录,可能是由捆绑程序创建的,所以我手动复制到了 Rails 根目录。
现在,rake/rails 可以工作了。
bundle show twitter
显示.../shared/bundle/ruby/1.9.1/gems/twitter-1.7.1
。
但是,重新部署会让我回到 (1),因为 .bundle 目录不存在。
具体问题:
- 我需要手动创建/复制 .bundle/config 吗?
- 我需要手动将 Gemfile/Gemfile.lock 复制到共享目录吗?如果我添加宝石会发生什么?我应该保留两份副本,还是手动/以编程方式同步它们?
- 我做错了什么?
谢谢!
I got the server with the configuration above.
This is the important part of my deploy.rb recipe:
$:.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:
* 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. I ran bundle install
locally first to generate the .lock file. But the bundler/capistrano points to /mnt/data-store/project/releases/shared/Gemfile so I just copied manually both files there. 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
Your bundle is complete! It was installed into /mnt/data-store/project/shared/bundle
in the output.
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
.
Proceeding with my adventure, I discovered that once you have .bundle/config withBUNDLE_PATH: /mnt/data-store/project/shared/bundle
It works.
I had this directory, probably created by bundler, under /mnt/data-store/releases/shared/
, so I copied manually to the rails root.
Now, rake/rails c work.
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.
Concrete questions:
- Do I need to create/copy .bundle/config manually?
- Do I need to copy Gemfile/Gemfile.lock manually to the shared dir? What happens if I add gems? Should I hold two copies, or manually/programmatically sync them?
- WHAT AM I DOING WRONG?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看deployment.rb 文件中的这一部分(Bundler 代码),
有一个名为
:current_release
的键,由于某种原因,该键可能没有在 Capistrano 中正确设置。捆绑程序中的
:current_release
将指向“共享”文件夹,而不是最新版本(带有时间戳)。这将在“deploy:finalize_update”之前
执行。
为了解决这个问题,我要做的就是在这个事件上添加你自己的钩子。
这是实际的方法
Look at this part in the deployment.rb file (Bundler code)
There's a key called
:current_release
, this key is probably not being set correctly with Capistrano for some reason.the
:current_release
in bundler will point to the "shared" folder instead of the latest release (with the timestamp)This is getting executed on
before 'deploy:finalize_update'
.What I would do in order to fix this is to add your own hook on this event.
And this is the actual method
错误
当服务器上的发布目录中有不需要的内容时,就会发生 。应该只包含应用程序的早期版本的目录(它们的名称以日期开头,看起来像 20111025125442)。
因此,请删除不需要的目录或文件,然后尝试再次部署。
Error
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).
So, remove unwanted directories or files and then try to deploy again.