[英]capistrano not using rails environment with bundler properly
我正在尝试首次设置Capistrano部署,我想先在开发目录中对其进行测试,然后再尝试将其投入生产。 通常,在开发环境中,我什至都不会为Capistrano烦恼,但是在部署时会遇到问题。 似乎Capistrano要:
A)运行bundle命令: bundle --without development test
和
B)运行rake assets:precompile
在开发环境中进行rake assets:precompile
。 我不要 我为什么要? 如果我想这样做,也许可以在“暂存”环境中进行,但肯定不能在开发模式下进行。
当前最大的障碍是,它捆绑了其认为处于生产模式的信息,因此跳过了在预编译资产时确实使用开发环境时所需的gem。
编辑:这是两个正在运行的脚本的示例-第一个脚本就像在生产环境中一样运行bundler,最后一个在开发环境中运行它(RAILS_ENV = development)。 我们当然会收到错误消息,因为BetterErrors是仅在开发环境中加载的gem,因此,由于对bundle
的调用是在生产环境中而找不到BetterErrors。
INFO [9797fc64] Running ~/.rvm/bin/rvm default do bundle install --binstubs /home/vps_user/rails_deployments/dev.www/shared/bin --path /home/vps_user/rails_deployments/dev.www/shared/bundle --without development test --deployment --quiet on localhost
DEBUG [9797fc64] Command: cd /home/vps_user/rails_deployments/dev.www/releases/20140217224858 && ~/.rvm/bin/rvm default do bundle install --binstubs /home/vps_user/rails_deployments/dev.www/shared/bin --path /home/vps_user/rails_deployments/dev.www/shared/bundle --without development test --deployment --quiet
INFO [9797fc64] Finished in 1.883 seconds with exit status 0 (successful).
DEBUG [da905ff7] Running /usr/bin/env if test ! -d /home/vps_user/rails_deployments/dev.www/releases/20140217224858; then echo "Directory does not exist '/home/vps_user/rails_deployments/dev.www/releases/20140217224858'" 1>&2; false; fi on localhost
DEBUG [da905ff7] Command: if test ! -d /home/sprvps_userucewo/rails_deployments/dev.www/releases/20140217224858; then echo "Directory does not exist '/home/vps_user/rails_deployments/dev.www/releases/20140217224858'" 1>&2; false; fi
DEBUG [da905ff7] Finished in 0.044 seconds with exit status 0 (successful).
INFO [0562438c] Running ~/.rvm/bin/rvm default do bundle exec rake assets:precompile on localhost
DEBUG [0562438c] Command: cd /home/vps_user/rails_deployments/dev.www/releases/20140217224858 && ( RAILS_ENV=development ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG [0562438c] rake aborted!
DEBUG [0562438c] uninitialized constant BetterErrors
我的设置有问题吗? 我使用Capistrano v3 +,并在rvm中使用Ruby v2.1.0。
的Gemfile:
if RUBY_PLATFORM !~ /mingw/
gem 'capistrano-rails'
gem 'capistrano-rvm'
gem 'capistrano-bundler'
end
Capfile:
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
deploy.rb:
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'website'
set :repo_url, 'git@bitbucket.org:MyUserName/website.git'
set :user, 'vps_user'
set :tmp_dir, '/home/vps_user/tmp'
# Default value for keep_releases is 5
set :keep_releases, 3
SSHKit.config.command_map[:rake] = "bundle exec rake"
SSHKit.config.command_map[:rails] = "bundle exec rails"
# Common directories (usually assets)
set :linked_dirs, %w{ public/assets/emails public/assets/events public/assets/photographs public/assets/updates public/assets/video public/assets/wines }
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
部署/ development.rb
set :branch, :develop
set :stage, :development
set :rails_env, 'development'
set :deploy_to, '/home/vps_user/rails_deployments/dev.www'
server 'localhost', user: 'vps_user', roles: %w{web app}
部署/ production.rb
set :branch, :master
set :stage, :production
set :rails_env, 'production'
set :deploy_to, '/home/vps_user/rails_deployments/www'
server 'localhost', user: 'vps_user', roles: %w{web app}
我这样运行deploy命令: bundle exec cap development deploy
好的,所以在“用法”下查看Capistrano :: Bundler ,我在其中看到了一个叫做:bundle_without的选项,它看起来很有希望。 因此,我将set :bundle_without, 'production'
放入我的development.rb部署脚本中,它起作用了!
这并不能解决Capistrano一直试图生成预编译资产的问题,但是我敢肯定那里有解决方案,例如重写rake任务之类的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.