簡體   English   中英

capistrano沒有正確使用捆綁器的Rails環境

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM