Capistrano - 无法部署我的database.yml

[英]Capistrano - can't deploy my database.yml


When I try to deploy my app with capistrano, I'll get this error:

当我尝试使用capistrano部署我的应用程序时,我会收到此错误:

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

失败:IP_ADDR上的“sh -c'cp /var/www/my_app/releases/20120313115055/config/database.staging.yml /var/www/my_app/releases/20120313115055/config/database.yml'”

My database.yml ie empty, database.staging.yml:

我的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

in the /confing/deploy are files "production" "staging"

在/ confing / deploy中是文件“production”“staging”

What am I missing here/where should I look for a failure? The credentials to database on the server should be right.

我在这里缺少什么/我应该在哪里寻找失败?服务器上数据库的凭据应该是正确的。

EDIT - here is my deploy

编辑 - 这是我的部署

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

The problem:

问题:

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

3 个解决方案

#1


21  

I'm not sure how to solve your problem. It looks like database.staging.yml is not being deployed, so there's nothing for it to copy over.

我不知道如何解决你的问题。看起来好像没有部署database.staging.yml,因此没有任何内容可以复制。

I think there's a better workflow, though. Things like settings and database configs do not typically change between deployments, so those things can go in the shared folder of all the capistrano releases. Typically, you don't want your database.yml to be in your repo either since it's sensitive information. You can satisfy both of these things by excluding config/database.yml in your .gitignore.

不过,我认为有更好的工作流程。设置和数据库配置之类的东西通常不会在部署之间发生变化,因此这些东西可以放在所有capistrano版本的共享文件夹中。通常,您不希望您的database.yml在您的仓库中,因为它是敏感信息。您可以通过在.gitignore中排除config / database.yml来满足这两个条件。

This requires you to do a one time set up on your servers. You need create a database.yml at your_app_path/shared/config. Shared is a sibling to current and releases.

这要求您在服务器上进行一次设置。您需要在your_app_path / shared / config中创建database.yml。共享是当前和发布的兄弟。

Your deploy.rb should have a task that symlinks the newly deployed release's database.yml to the on in the shared directory. Like this:

您的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

This means that your repo will contain no database.yml files. Since they are probably already in your repo. You'll have to git rm them, commit. Add them to the .gitignore and commit that.

这意味着您的repo将不包含database.yml文件。因为他们可能已经在你的回购。你必须git rm他们,提交。将它们添加到.gitignore并提交。

#2


8  

In Capistrano 3, linking files is built-in. John's answer is simply:

在Capistrano 3中,链接文件是内置的。约翰的答案很简单:

  • In the shared/ folder create config/database.yml
  • 在shared /文件夹中创建config / database.yml
  • In config/deploy.rb use this line

    在config / deploy.rb中使用此行

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

This does what John was saying.

这就是约翰所说的。

#3


0  

If you don't need to "reference application objects or methods"(1) during precompile then you might be OK with setting config.assets.initialize_on_precompile to false in config/application.rb

如果在预编译期间不需要“引用应用程序对象或方法”(1),那么在config / application.rb中将config.assets.initialize_on_precompile设置为false可能没问题。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2012/03/13/e7839bd908cc6bcce405b8885e1f3179.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告