2012-03-13 34 views
8

當我嘗試部署我與Capistrano的應用程序,我會得到這個錯誤:Capistrano的 - 不能部署我的database.yml

failed: "sh -c 'cp /var/www/my_app/releases/20120313115055/config/database.staging.yml /var/www/my_app/releases/20120313115055/config/database.yml'" on IP_ADDR

的database.yml即空,database.staging .yml

production: 
    adapter: mysql2 
    encoding: utf8 
    reconnect: false 
    database: my_db 
    pool: 15 
    username: my_user_name 
    password: my_pass 
    host: localhost 
/confing

/部署是文件的 「生產」, 「分期」

我在這裏錯過了什麼/我應該在哪裏尋找失敗?服務器上的數據庫憑據應該是正確的。

編輯 - 這裏是我的部署

set :application, "my_app" 
set :repository, "https://IP_ADDR/svn/my_app" 

set :scm, :subversion 
set :scm_username, 'my_name' 
set :scm_password, 'my_pass' 

default_run_options[:pty] = true 

set :user, "my_name" 
set :domain, 'IP_ADDR' 

set :deploy_to, "/var/www/my_app" 

set :use_sudo, false 
set :deploy_via, :remote_cache 
#set :keep_releases, 1 

set :rails_env, 'production' 

role :web, domain 
role :app, domain 
role :db, domain, :primary => true # This is where Rails migrations will run 

namespace :deploy do 

    task :build_gems, :roles => :app do 
     desc "Building gems" 
     run "cd #{release_path} && bundle install --deployment" 
    end 

    task :migrations do 
     desc "Migrating database" 
     run "cd #{release_path} && rake db:migrate RAILS_ENV=production" 
    end 

    [:start, :stop].each do |t| 
     desc "#{t} task is a no-op with passenger" 
     task t, :roles => :app do ; end 
    end 

    desc "Restarting passenger with restart.txt" 
    task :restart, :roles => :app, :except => { :no_release => true } do 
     run "touch #{release_path}/tmp/restart.txt" 
    end 

    after "deploy:update_code", "deploy:build_gems", "db:copy_configuration", "config:copy", "deploy:migrations", "deploy:cleanup" 
    after "deploy:update", "bluepill:copy_config", "bluepill:restart" 
end 

namespace :db do 
    task :copy_configuration do 
     run "cp #{release_path}/config/database.staging.yml #{release_path}/config/database.yml" 
    end 
end 

namespace :config do 
    task :copy do 
     run "cp #{release_path}/config/config.staging.yml #{release_path}/config/config.yml" 
    end 
end 

namespace :bluepill do 
    desc "Restart bluepill process" 
    task :restart, :roles => [:app] do 
    run "#{release_path}/script/delayed_job stop" 
    sudo "/etc/init.d/bluepill.sh restart" 
    end 

    #desc "Load bluepill configuration and start it" 
    ##task :start, :roles => [:app] do 
    # sudo "/etc/init.d/bluepill.sh start" 
    #end 

    desc "Prints bluepills monitored processes statuses" 
    task :status, :roles => [:app] do 
    sudo "bluepill status" 
    end 

    desc "Copy config" 
    task :copy_config, :roles => [:app] do 
    run "cp #{release_path}/config/bluepill/configuration.rb /srv/script/bluepill.rb" 
    end 
end 

問題:

cp: cannot stat `/var/www/my_app/releases/20120313144907/config/database.staging.yml': No such file or directory 
+0

當您在該機器上手動運行cp命令時會發生什麼情況? – 2012-03-13 13:18:13

+1

.yml或.ymp?如果你的.ymp文件被錯誤地命名爲 – DGM 2012-03-13 13:19:45

+0

.yml,我的不好... – user984621 2012-03-13 13:25:22

回答

21

我不知道如何解決你的問題。它看起來像database.staging.yml沒有被部署,所以沒有什麼可以複製。

但我認爲這有一個更好的工作流程。像設置和數據庫配置之類的事情通常不會在部署之間發生變化,所以這些事情可以在所有Capistrano版本的共享文件夾中進行。通常情況下,你不希望你的database.yml在你的repo中,因爲它是敏感信息。您可以通過在您的.gitignore中排除config/database.yml來滿足這兩個要求。

這需要您在服務器上設置一次。您需要創建一個database.ymlyour_app_path/shared/config。共享是當前和發佈的兄弟。

您的deploy.rb應該有一個任務,將新部署的版本database.yml符號鏈接到共享目錄中的on。就像這樣:

before "deploy:assets:precompile" do 
    run ["ln -nfs #{shared_path}/config/settings.yml #{release_path}/config/settings.yml", 
     "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml", 
     "ln -fs #{shared_path}/uploads #{release_path}/uploads" 
    ].join(" && ") 
end 

這意味着你的回購不包含任何database.yml文件。因爲他們可能已經在你的回購。你必須要git rm他們,提交。將它們添加到.gitignore並確認。

+1

我們這樣做了,但在config中包含了一個database.yml.example,開發人員可以使用它在本地進行本地化,而無需猜測database.yml設置 – tehfoo 2013-03-01 23:47:05

+0

我認爲current/config/database.yml是鏈接到shared/config/database.yml如果shared/config/database.yml丟失,它會給你'沒有這樣的文件或目錄'。我們可以手動創建它到shared/config/database.yml並進行部署。這東西在這裏工作。 – vajapravin 2013-04-02 07:48:14

+0

對不起,你的'deploy.rb'腳本爲什麼提到'settings.yml'? – Matthias 2016-03-06 00:10:51

0

如果您不需要時預編譯,然後「參考應用程序對象或方法」(1),你可能會在config/application.rb

8

在Capistrano的3設置config.assets.initialize_on_precompilefalse OK,鏈接文件是內置。約翰的回答很簡單:

  • shared/文件夾中創建config/database.yml
  • config/deploy.rb使用此行

    set :linked_files, fetch(:linked_files, []).push('config/database.yml') 
    

這不會有什麼約翰說。

+0

就是這樣。謝謝 – Francisco 2016-08-11 22:58:45

+0

我們如何解決最新版本3.8.0的問題? – 2017-03-20 12:41:13