【问题标题】:1st deploy - need to install all gems on the server第一次部署 - 需要在服务器上安装所有 gem
【发布时间】:2012-02-07 20:34:23
【问题描述】:

我正在尝试将 1 次部署到服务器 ( cap deploy:cold ) 并且它一直要求我安装 gems。举个例子:

*** [err :: ip-address] Could not find net-ssh-2.3.0 in any of the sources

我有什么办法可以一次性安装所需的所有 gem?

这是我的 deploy.rb 文件和 gemfile:

部署.rb

    set :application, "myapp"
set :repository,  "repo goes here"
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`

role :web, "ipaddress"                          # Your HTTP server, Apache/etc
role :app, "ipaddress"                          # This may be the same as your `Web` server
role :db,  "ipaddress", :primary => true # This is where Rails migrations will run
# role :db,  "your slave db-server here"

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

set :deploy_to, "/home/deploy/#{application}"
set :rails_env, 'production'
set :branch, "master"

set :scm, :git
set :user, "user"
set :runner, "user"
# ssh_options[:port] = 2232
set :use_sudo, false
set :normalize_asset_timestamps, false


# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

namespace :bundler do
  task :create_symlink, :roles => :app do
    shared_dir = File.join(shared_path, 'bundle')
    release_dir = File.join(current_release, '.bundle')
    run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
  end

  task :bundle_new_release, :roles => :app do
    bundler.create_symlink
    run "cd #{release_path} && bundle install --without test"
  end

  task :lock, :roles => :app do
    run "cd #{current_release} && bundle lock;"
  end

  task :unlock, :roles => :app do
    run "cd #{current_release} && bundle unlock;"
  end
end

 after "deploy", "deploy:cleanup"

namespace :deploy do

    desc "Restarting mod_rails with restart.txt"
    task :restart, :roles => :app, :except => { :no_release => true } do
        run "touch #{current_path}/tmp/restart.txt"
    end

    [:start, :stop].each do |t|
        desc "#{t} task is a no-op with mod_rails"
        task t, :roles => :domain do ; end
    end
end

task :after_update_code do  
 run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end

宝石文件:

source 'http://rubygems.org'

gem 'rails', '3.1.3'

# Bundle edge Rails instead:
# gem 'rails',     :git => 'git://github.com/rails/rails.git'



gem 'json'
gem 'rake', '0.9.2.2'
gem 'mysql2'
gem 'capistrano'
gem 'therubyracer'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.1.5'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

【问题讨论】:

  • 这篇文章可能对你有所帮助:stackoverflow.com/questions/7706485/…
  • 谢谢,我看到了 - 我的机器上确实有捆绑器,但我的应用尚未部署,所以我无法捆绑安装。
  • 试试我在下面添加的答案,我没有看到您的 deploy.rb 文件中包含“bundler/capistrano”
  • 在你的 nginx.conf 中验证 passanger_ruby 是否与 capistrano 使用的相同。 whereis ruby 显示所有可用,which ruby 显示当前环境。使用 ssh 登录并手动执行是否有效?
  • whereis ruby​​ ruby​​: /usr/local/bin/ruby and /opt/ruby/bin/ruby, then for which ruby​​ /opt/ruby/bin/ruby 是的,当我手动捆绑安装时一切 - 我将 github 添加到 gem 源中,这有助于安装所有依赖项,但仍然不会通过 deploy 安装它们。

标签: ruby-on-rails-3 deployment capistrano


【解决方案1】:

如果你改变这一行

run "cd #{release_path} && bundle install --without test"

run "cd #{release_path} && bundle install --path=you_gem_path --without #{bundle_without.join(' ')}"

你可以通过运行找到你的 gem 路径

$ echo $GEM_PATH

您还必须设置 bundle_without 你可以在文件的开头设置它

set :bundle_without,      [:development, :test]

【讨论】:

    【解决方案2】:

    尝试将此添加到您的 deploy.rb

    set :bundle_without, [:development, :test]
    require 'bundler/capistrano'
    

    【讨论】:

    • 我试过了,但仍然得到:** [out :: ip-address] 在任何来源中都找不到 net-ssh-2.3.0
    • 嗯,这真的很奇怪,我以为可以做到。你检查过这个页面吗? gembundler.com/deploying.html
    • 我刚刚在底部注意到了这个错误: failed: "env PATH=/opt/ruby/bin/:$PATH sh -c 'cd /home/deploy/tomahawk/releases/20120207210055 && bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'"
    • 尝试将 bundler(如果还没有这个版本)升级到版本 1.0.18。那应该根据这个来解决它:github.com/capistrano/capistrano/issues/81
    • 是的,我有最新版本,但我注意到它正在尝试这样做:[err :: ip+address] find: `/home/deploy/myapp/releases/20120208011538/public/images' - public 目录下没有images文件夹?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 2015-03-26
    • 2015-12-13
    • 2020-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多