2014-03-19 50 views
0

首先,當談到Rails和Capistrano時,我是一個初學者。 我的開發環境在沒有任何問題的情況下運行,我想先嚐試將它作爲本地虛擬機上的測試環境,並使用與我的生產服務器相同的設置。Capistrano,Rails「gem is loaded。Add`gem'sqlite3'` to your Gemfile'

我選擇Capistrano來處理部署,並根據官方網站的教程設置一切。

的規格是:

  • ubuntu的
  • 紅寶石2.0.0-P247
  • 導軌4.1.0.beta1
  • Capistrano的3
  • PHUSION乘客

我的Gemfile:

gem 'rails', '4.1.0.beta1' 
gem 'rails-i18n', '~> 4.0.0' 

group :assets do 
    # Use SCSS for stylesheets 
    gem 'sass-rails', '4.0.2' 

    gem 'uglifier', '>= 1.3.0' 
end 

gem 'bourbon' 
gem 'foundation-rails' 

group :development do 

    gem 'capistrano', '~> 3.0.1' 
    gem 'net-ssh', '~> 2.7.0' 
    gem 'capistrano-rails', '~> 1.1.0' 
    gem 'capistrano-bundler' 
    gem 'capistrano-rvm' 
    gem 'capistrano-rbenv', "~> 2.0" 
end 

group :development, :test do 
    gem 'sqlite3' 
    gem 'rspec-rails' 
end 

group :test, :production do 
# gem 'mysql2' 
end 

gem 'jquery-rails' 

我deploy.rb文件:

set :application, 'appliname' 
set :deploy_user, 'deploy' 
set :use_sudo, false 
set :repo_url, '[email protected]:path/to/project.git' 
set :branch, "master" 

set :scm, :git 

# set :format, :pretty 
# set :log_level, :debug 
set :pty, true 

# setup rvm. 
set :rbenv_type, :system 
set :rbenv_ruby, 'ruby-2.0.0-p247' 
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" 
set :rbenv_map_bins, %w{rake gem bundle ruby rails} 

# files we want symlinking to specific entries in shared. 
set :linked_files, %w{config/database.yml config/private_env.yml} 

# dirs we want symlinking to shared 
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} 

# set :default_env, { path: "/opt/ruby/bin:$PATH" } 
set :keep_releases, 5 

namespace :deploy do 

    # make sure we're deploying what we think we're deploying 
    # only allow a deploy with passing tests to deployed 
    # before :deploy, "deploy:run_tests" 

    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 :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 

    # compile assets locally then rsync 
    # after 'deploy:symlink:shared', 'deploy:compile_assets' 
    # after :finishing, 'deploy:cleanup' 

end 

部署/ test.rb

set :stage, :test 

server 'testserver.local', user: fetch(:deploy_user), roles: %w{web app db} 
set :deploy_to, '/home/project/public' 
set :enable_ssl, false 

我的database.yml 起初我想使用MySQL甚至對我的測試環境,但對於部署調試的緣故,我暫時放了sqlite。

default: &default 
    adapter: sqlite3 
    pool: 5 
    timeout: 5000 

development: 
    <<: *default 
    database: db/development.sqlite3 

test: &test 
    <<: *default 
    database: db/test.sqlite3 
# adapter: mysql2 
# encoding: utf8 
# reconnect: true 
# database: ENV['database'] 
# pool: 5 
# username: ENV['username'] 
# password: ENV['password'] 
# host: localhost 

production: 
    <<: *test 

最後運行以下deply命令後的錯誤消息:

cap test deploy 

錯誤:

DEBUG [f012bc9e] Command: cd /home/project/public/releases/20140319125218 && (RAILS_ENV=test bundle exec rake assets:precompile) 
DEBUG [f012bc9e] rake aborted! 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activerecord-4.1.0.beta1/lib/active_record/connection_adapters/connection_specification.rb:58:in `rescue in resolve_hash_connection' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activerecord-4.1.0.beta1/lib/active_record/connection_adapters/connection_specification.rb:55:in `resolve_hash_connection' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activerecord-4.1.0.beta1/lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activerecord-4.1.0.beta1/lib/active_record/connection_adapters/connection_specification.rb:30:in `spec' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activerecord-4.1.0.beta1/lib/active_record/connection_handling.rb:39:in `establish_connection' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activerecord-4.1.0.beta1/lib/active_record/railtie.rb:126:in `block (2 levels) in <class:Railtie>' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:27:in `each' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support/lazy_load_hooks.rb:27:in `on_load' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activerecord-4.1.0.beta1/lib/active_record/railtie.rb:124:in `block in <class:Railtie>' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/railties-4.1.0.beta1/lib/rails/initializable.rb:30:in `instance_exec' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/railties-4.1.0.beta1/lib/rails/initializable.rb:30:in `run' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ 
DEBUG [f012bc9e] ruby/2.0.0/gems/railties-4.1.0.beta1/lib/rails/initializable.rb:55:in `block in run_initializers' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/railties-4.1.0.beta1/lib/rails/initializable.rb:54:in `run_initializers' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/railties-4.1.0.beta1/lib/rails/application.rb:285:in `initialize!' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/releases/20140319125218/config/environment.rb:8:in `<top (required)>' 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:247:in `require' 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:247:in `block in require' 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:232:in `load_dependency' 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:247:in `require' 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/railties-4.1.0.beta1/lib/rails/application.rb:261:in `require_environment!' 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/railties-4.1.0.beta1/lib/rails/application.rb:344:in `block in run_tasks_blocks' 
DEBUG [f012bc9e] /home/project/public/shared/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define' 
DEBUG [f012bc9e] Tasks: TOP => environment 
DEBUG [f012bc9e] 
DEBUG [f012bc9e] (See full trace by running task with --trace) 
DEBUG [f012bc9e] 
cap aborted! 
rake stdout: Nothing written 
rake stderr: Nothing written 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/command.rb:94:in `exit_status=' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:142:in `block (4 levels) in _execute' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:551:in `call' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:551:in `do_request' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:561:in `channel_request' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:269:in `wait' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:164:in `block (2 levels) in _execute' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:514:in `call' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:514:in `do_open_confirmation' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:545:in `channel_open_confirmation' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:166:in `block in _execute' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `tap' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:123:in `_execute' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:66:in `execute' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-rails-1.1.1/lib/capistrano/tasks/assets.rake:59:in `block (6 levels) in <top (required)>' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/abstract.rb:89:in `with' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-rails-1.1.1/lib/capistrano/tasks/assets.rake:58:in `block (5 levels) in <top (required)>' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/abstract.rb:81:in `within' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/capistrano-rails-1.1.1/lib/capistrano/tasks/assets.rake:57:in `block (4 levels) in <top (required)>' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run' 
/Users/username/.rvm/gems/ruby-2.0.0-p247/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute' 
Tasks: TOP => deploy:assets:precompile 
(See full trace by running task with --trace) 
The deploy has failed with an error: #<SSHKit::Command::Failed: rake stdout: Nothing written 
rake stderr: Nothing written 

因此,基本上,不管是用MySql2寶石或sqlite的寶石,我有同樣的錯誤... 我完全失去了,一直在網上查找,並沒有用多個測試。

很明顯,我已經在dev計算機的「軟件包更新」和「軟件包安裝」上運行。 但我想所有這些命令都由Capistrano在部署時自動運行。

所以,如果一個良好的靈魂可以在這方面幫助那會使我很高興,我可能會停止失去我的頭髮(或沒有):)

如果需要更多的信息,請諮詢! 謝謝

+0

警告:你有rvm和rbenv的寶石。這兩個Ruby環境管理系統不能很好地協作。 – wurde

+0

我不知道,我想我會刪除rbenv,這樣我就可以在我的環境中保持一致。謝謝 – hekigan

+0

當然。如果你沒有對兩者進行比較,花幾分鐘時間看看你喜歡哪一個。 – wurde

回答

1

您的sqlite3寶石沒有被加載生產,因爲你已經在Gemfile中找到它。將它從任何組中移出,或將其移至group :test, :production組。

+0

謝謝,它確實有效,但我有點困惑。 到目前爲止,在「group:development,:test」中這應該是正確的,因爲我在推測:測試環境中... 爲什麼這樣錯了? – hekigan

+0

因爲當capistrano部署時,它將在生產環境下執行「捆綁安裝」。由於'sqlite3' gem只在開發和測試組中使用,所以bundler沒有安裝它。因此,當需要創建寶石時,部署失敗。 – croceldon

+0

我明白了,但我目前正在推行:測試環境。這個測試失敗了。 我還沒有在生產環境中推送。 :) – hekigan