Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails capistrano未正确地将rails环境与bundler一起使用_Ruby On Rails_Capistrano_Bundler - Fatal编程技术网

Ruby on rails capistrano未正确地将rails环境与bundler一起使用

Ruby on rails capistrano未正确地将rails环境与bundler一起使用,ruby-on-rails,capistrano,bundler,Ruby On Rails,Capistrano,Bundler,我第一次尝试设置Capistrano部署,我想在生产环境中尝试之前在我的开发目录中测试它。通常情况下,我甚至不会在开发环境中使用Capistrano,但我在部署时遇到了问题。卡皮斯特拉诺似乎想: A) 运行bundle命令:bundle——不进行开发测试 及 B) 在开发环境中运行rake资产:预编译。我不想那样。我为什么要这么做?如果我想这样做,也许是在“登台”环境中,但肯定不是在开发模式中 目前最大的障碍是,它认为自己处于生产模式,因此跳过了在预编译资产时正确使用开发环境所需的gem 编辑:

我第一次尝试设置Capistrano部署,我想在生产环境中尝试之前在我的开发目录中测试它。通常情况下,我甚至不会在开发环境中使用Capistrano,但我在部署时遇到了问题。卡皮斯特拉诺似乎想:

A) 运行bundle命令:
bundle——不进行开发测试

B) 在开发环境中运行rake资产:预编译。我不想那样。我为什么要这么做?如果我想这样做,也许是在“登台”环境中,但肯定不是在开发模式中

目前最大的障碍是,它认为自己处于生产模式,因此跳过了在预编译资产时正确使用开发环境所需的gem

编辑:这里有两个运行的脚本示例——第一个脚本运行bundler,就像我们在生产环境中一样,最后一个脚本在开发环境中运行(RAILS_ENV=development)。我们当然会遇到错误,因为BetterErrors是一个仅在开发环境中加载的gem,因此它无法找到更好的错误,因为对
bundle
的调用是在生产环境中进行的

 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
我的设置有问题吗?我正在使用CapistranoV3+,在rvm中使用RubyV2.1.0


Gemfile:

if RUBY_PLATFORM !~ /mingw/
    gem 'capistrano-rails'
    gem 'capistrano-rvm'
    gem 'capistrano-bundler'
end
# 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 }
# 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
Capfile:

if RUBY_PLATFORM !~ /mingw/
    gem 'capistrano-rails'
    gem 'capistrano-rvm'
    gem 'capistrano-bundler'
end
# 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 }
# 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
deploy.rb:

if RUBY_PLATFORM !~ /mingw/
    gem 'capistrano-rails'
    gem 'capistrano-rvm'
    gem 'capistrano-bundler'
end
# 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 }
# 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
部署/开发.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}
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}
部署/生产.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}
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

好的,所以在“用法”下面我看到了一个选项,名为:bundle\u without,看起来很有希望。所以我在development.rb deploy脚本中放入了没有“production”的
set:bundle\u,它成功了

这并不能解决Capistrano一直试图生成预编译资产的问题,但我确信有一个解决方案,比如重写rake任务或其他什么