【问题标题】:Deploying Rails App to a VPS using Capistrano from Windows to Linux使用 Capistrano 从 Windows 到 Linux 将 Rails 应用程序部署到 VPS
【发布时间】:2013-02-06 21:14:21
【问题描述】:

我正在尝试将我的第一个 Rails 应用程序部署到 VPS。到目前为止,我已经使用 ubuntu、postgresql、node、ruby 等进行了所有配置,并且运行 cap deploy:setup 命令没有错误。当我尝试运行cap deploy:cold 时,我收到一个有趣的捆绑程序错误,它说由于缺少gem 而无法继续,即使它在gemfile 中。我正在 Windows 7 上开发,因此无法与 unicorn 捆绑,并将此 gem 放入 gem 文件中的组中:

group :production do
    if RUBY_PLATFORM =~ /win32/
      gem "pg", :platform => [:mswin, :mingw]
    else
      gem "pg", :platform => :ruby
      gem 'unicorn'
    end
end

这是我运行cap deploy:cold时得到的一些输出:

    ?[2;37mcommand finished in 200ms?[0m
 ** transaction: commit
  * ?[32m2013-02-06 21:11:42 executing `deploy:migrate'?[0m
  * ?[33mexecuting "cd /home/deployer/apps/blog/releases/20130206211131 && bundl
e exec rake RAILS_ENV=production  db:migrate"?[0m
    servers: ["176.58.109.176"]
    [176.58.109.176] executing command
 ** [out :: 176.58.109.176] rake aborted!
 ** [out :: 176.58.109.176] Please install the postgresql adapter: `gem install
activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfil
e.)
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.
rb:7:in `<top (required)>'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in requ
ire'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependen
cy'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection
_specification.rb:50:in `resolve_hash_connection'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection
_specification.rb:41:in `resolve_string_connection'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection
_specification.rb:25:in `spec'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection
_specification.rb:130:in `establish_connection'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activerecord-3.2.11/lib/active_record/railtie.rb:82:in `block (2 levels) in <
class:Railtie>'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:36:in `instance_ev
al'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:36:in `execute_hoo
k'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:43:in `block in ru
n_load_hooks'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:42:in `each'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:42:in `run_load_ho
oks'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activerecord-3.2.11/lib/active_record/base.rb:720:in `<top (required)>'
 ** [out :: 176.58.109.176] /home/deployer/apps/blog/shared/bundle/ruby/1.9.1/ge
ms/activerecord-3.2.11/lib/active_record/railties/databases.rake:25:in `block (2
 levels) in <top (required)>'
 ** [out :: 176.58.109.176] Tasks: TOP => db:migrate => db:load_config
 ** [out :: 176.58.109.176] (See full trace by running task with --trace)
    ?[2;37mcommand finished in 2926ms?[0m
failed: "sh -c 'cd /home/deployer/apps/blog/releases/20130206211131 && bundle ex
ec rake RAILS_ENV=production  db:migrate'" on 176.58.109.176

非常感谢任何帮助,经过几天的努力,我已经准备好放弃了!非常感谢。

【问题讨论】:

  • 假设您的服务器正在运行 Linux(我猜),您为什么不简单地更改为 gem 'pg' ?您不需要指定:platform,也不需要 if .. else ..end .
  • 您好,谢谢您的回复!当我查看 Gemfile.lock 时,我注意到它安装了一个 windows 版本的 pg,所以我认为当它被部署在 linux 服务器上时,将它置于条件中不会造成任何伤害?
  • 根据日志,您的部署似乎条件失败。尽可能保持简单。
  • 大家好,感谢您的回复。更改为 group :production do gem "pg", :platform =&gt; :ruby gem 'unicorn' end 但仍然出现相同的错误。让我觉得它可能没有部署为生产环境?
  • 也试过group :production do gem 'pg' gem 'unicorn' end 并收到同样的错误。

标签: ruby-on-rails gem capistrano bundler


【解决方案1】:

在你的Gemfile:

group :production do 
  gem 'pg'
  gem 'unicorn'
end

删除:platform =&gt; :ruby

编辑:尝试指定服务器上的环境:

export RAILS_ENV=production

【讨论】:

  • 您好,谢谢您的回答。我不能拥有gem 'unicorn',因为它需要kgio,它与Windows 不兼容,它会导致本地包失败。
  • 如果您不想安装 linux,我建议您切换到带有 Linux 的 VirtualBox。胜利是一种持续的痛苦。
  • 大约一年前,我放弃了尝试在 Windows 上进行 Rails 工作。它可能会诱使您认为它将是稳定的,但在任何时候新的 gem 安装都会破坏您的 windows 开发设置。直接进入 Ubuntu Virtual Box,省去很多麻烦。
  • 您好,感谢您的修改。尝试过,捆绑它,提交它,运行cap deploy:cold 并得到同样的错误。完全没有意义!
  • 你能发帖database.yml吗?
猜你喜欢
  • 2012-06-17
  • 2012-09-08
  • 1970-01-01
  • 2013-09-29
  • 1970-01-01
  • 2019-04-27
  • 1970-01-01
  • 2017-03-16
  • 2013-06-22
相关资源
最近更新 更多