2013-10-25 37 views
15

當我開始Capistrano的3,軌道4,數據庫配置不指定適配器

帽生產部署

失敗是這樣的:

DEBUG [4ee8fa7a] Command: cd /home/deploy/myapp/releases/releases/20131025212110 && (RVM_BIN_PATH=~/.rvm/bin RAILS_ENV= ~/.rvm/bin/myapp_rake assets:precompile) 
DEBUG [4ee8fa7a]  rake aborted! 
DEBUG [4ee8fa7a]  database configuration does not specify adapter 

你可以看到「 RAILS_ENV =「實際上是空的,我想知道爲什麼會發生這種情況?我認爲這是後一個錯誤的原因,我沒有數據庫配置。

的deploy.rb文件如下:

set :application, 'myapp' 
set :repo_url, '[email protected]:developer/myapp.git' 
set :branch, :master 
set :deploy_to, '/home/deploy/myapp/releases' 
set :scm, :git 
set :devpath, "/home/deploy/myapp_development" 
set :user, "deploy" 
set :use_sudo, false 
set :default_env, { rvm_bin_path: '~/.rvm/bin' } 

set :keep_releases, 5 

namespace :deploy do 
    desc 'Restart application' 
    task :restart do 
    on roles(:app), in: :sequence, wait: 5 do 
     # Your restart mechanism here, for example: 
     within release_path do 
     execute " bundle exec thin restart -O -C config/thin/production.yml" 
     end 
    end 
    end 

    after :restart, :clear_cache do 
    on roles(:web), in: :groups, limit: 3, wait: 10 do 
     within release_path do 

     end 
    end 
    end 

    after :finishing, 'deploy:cleanup' 
end 

的database.yml:

production: 
    adapter: mysql2 
    encoding: utf8 
    database: myapp_production 
    pool: 5 
    username: user 
    password: pass 
    host: localhost 

development: 
    adapter: mysql2 
    encoding: utf8 
    database: myapp_development 
    pool: 5 
    username: user 
    password: pass 
    host: localhost 

的問題解決了,如果我添加

set :rails_env, "production" 

我deploy.rb,但是這看起來像我硬編碼,我相信有一個更好的解決方案。

+0

你可以發佈你的'database.yml'嗎?它應該包含數據庫適配器的「生產」部分。 –

+0

我將它添加到描述中。 – Kazmin

+0

如果'gem「mysql2」'聲明在'group:production do ... end'內,我建議再檢查一下'Gemfile'。 –

回答

17

編輯:每this pull request,它現在固定在capistrano-rails1.1.0版本。

this Github issue,另一個修復方法是編輯您的Capfile。註釋掉這兩條線

 
#require 'capistrano/rails/assets' 
#require 'capistrano/rails/migrations' 

,並把此行

 
require 'capistrano/rails' 

這將正確設置你的RAILS_ENV變量。

+0

太棒了。魔法... :/ – yekta

1

如果添加了一個文件,會發生什麼:

deploy/production.rb 

這一行:

set :stage, :production 
+0

我有那個文件 – Kazmin

7

似乎是在Capistrano的護欄的錯誤。

有,要麼從RAILS_ENV或舞臺佈景環境任務(rails.rake):

namespace :deploy do 
    before :starting, :set_rails_env do 
    set :rails_env, (fetch(:rails_env) || fetch(:stage)) 
    end 
end 

但這個任務並不即資產之前被稱爲:預編譯。因此:

namespace :assets do 
    task :precompile do 
    on roles :web do 
     within release_path do 
     with rails_env: fetch(:rails_env) do 
      execute :rake, "assets:precompile" 
     end 
     end 
    end 
    end 
end 

失敗,因爲如果未明確設置,rails_env爲零。

如果非要挖得更深一些,我會發送錯誤報告的時間。

8

基於馬克的答案,這肯定似乎是正確的,

,直到它被在此添加到您的config/deploy.rb上游固定就可以解決這個「命名空間:部署」塊:

desc 'Provision env before assets:precompile' 
    task :fix_bug_env do 
    set :rails_env, (fetch(:rails_env) || fetch(:stage)) 
    end 

    before "deploy:assets:precompile", "deploy:fix_bug_env" 

這將強制加載env和provisioning RAILS_ENV,然後調用資源:precompile。

11

上軌道4我得到了同樣的錯誤使用第3章和capistrano_rails;在部署環境文件(S),我設置

set :stage, :production 
set :rails_env, 'production' # even though doc says only need to do this if it's different 

文件位置:https://github.com/capistrano/rails

1

如果你使用的乘客,你需要添加

rails_env production; 

在Web服務器的(如:nginx的)的.conf您所指定的值passenger_rubypassenger_root地方。

相關問題