我正在将我的应用程序部署到一个新服务器上,该服务器已安装了所有内容。
我正在使用以下capistrano deploy.rb:
require "capistrano/ext/multistage"
require "bundler/capistrano"
set :default_environment, {
'ORACLE_HOME' => "/opt/oraclient/64/11.2.0.2/",
'LD_LIBRARY_PATH' => "$ORACLE_HOME/lib:/usr/local/lib",
'PATH' => "/opt/ruby/bin:$PATH:$ORACLE_HOME/bin"
}
SECURE_FILES = ['database.yml', 'ldap.yml', 'initializers/secret_token.rb']
set :application, "myapp"
set :use_sudo, false
set :scm, :git
set :repository, "ssh://git@hostname:7999/web/myapp.git"
set :user, "webuser"
set :deploy_via, :remote_cache
after "deploy:update_code", "custom:create_symlinks", "custom:assets_precompile", "custom:miscellaneous"
after "deploy", "deploy:migrate"
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 => :app do ; end
end
namespace :web do
desc "Enable maintenance mode for apache"
task :enable_maintenance, :role => :web do
run "mkdir -p #{shared_path}/system"
on_rollback { run "rm -f #{shared_path}/system/maintenance.html" }
page = File.read('public/maintenance.html')
put page, "#{shared_path}/system/maintenance.html", :mode => 0644
end
desc "Disable maintenance mode for apache"
task :disable_maintenance, :role => :web do
run "rm -f #{shared_path}/system/maintenance.html"
end
end
end
namespace :custom do
desc "Creating config, bundler-GEMS symlinks"
task :create_symlinks, :roles => :app do
#Secure Configuration File Symlinks
SECURE_FILES.each do |link|
fobj = "#{release_path}/config/#{link}"
run <<-CMD
if [ -e #{fobj} ]; then rm -f #{fobj}; fi;
rm -f #{previous_release}/config/#{fobj};
ln -s #{vormetric_path}/#{application}/#{link} #{fobj};
CMD
end
#Bundler GEM Installation Symlink
shared_bundler_dir = File.join(shared_path, 'bundle')
release_bundler_dir = File.join(current_release, 'vendor/bundle')
run "ln -s #{shared_bundler_dir} #{release_bundler_dir}"
end
desc "Assets Pre-Compilation"
task :assets_precompile, :roles => :app do
run "cd #{current_release} && RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
end
desc "Miscellaneous Tasks"
task :miscellaneous, :roles => :app do
run "chmod -f +w #{current_release}/db/schema.rb"
end
end
这是特定于box的部署脚本myhostname.rb:
server "myhostname",:app,:web,:db,:primary => true
set :deploy_to, "/opt/web/var/myapp"
set :rails_env, "customertest"
set :branch, "staging"
现在远程盒子不能访问互联网,但我有我所有的宝石存储在vendor/cache下。所以应该从这里开始。(vendor/cache在/myapp/current/vendor/cache下有nokigiri)
当我运行
,我得到以下错误:
** [out :: myhost] An error occurred while installing nokogiri (1.5.9), and Bundler cannot
** [out :: myhost] continue.
** [out :: myhost] Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.
应该部署代码的远程框设置了以下文件夹:
/opt/web/var/myapp
/opt/web/var/myapp/current(where all the code is cloned currently)
/opt/web/var/myapp/releases
/opt/web/var/myapp/shared
我不知道我应该如何拿起并安装gem.
这段话可能是相关的(强调我的):
http://bundler.io/v1.9/bundle_package.html默认情况下,如果你只是在运行bundle package之后运行bundle install, Bundler 仍然会连接到rubygems.org来检查vendor/cache中的任何gem是否存在平台特定的gem。可以通过运行bundle install——local来避免这种行为。请注意,这要求您为已缓存的所有gem提供正确的平台版本。最简单的方法是在同一台机器上运行bundle package,然后检入这些提供的gem。
所以,简而言之,当在生产服务器中运行bundler时,你需要传递——local标志,以避免连接到rubygems。
使用capistrano
的解决方案是在deploy.rb
文件中设置这个变量:
# deployment and quiet are used by default, we add the local flag
set :bundle_flags, "--deployment --quiet --local"