0

我正在尝试使用 capistrano 进行部署,但是我不断收到这个 database.yml not found 错误。我的 database.yml 文件未提交到我的存储库,我尝试设置我的 deploy.rb 文件以动态创建 database.yml,但它似乎没有工作。这是我的 deploy.rb 文件:

require "bundler/capistrano"

set :application, "myapp.com"
set :app_name, "myapp"
set :repository,  "git@bitbucket.org:myrepo/fltctr.git"
set :scm, :git

server "100.100.100.100", :web, :app, :db, primary: true

  set :user, "user" # As defined on your server
  set :password, "pwwd"
  set :deploy_to, "/var/www/html/myapp.com" # Directory in which the deployment will take place
  set :mysql_user, 'root_user'
  set :mysql_password, 'root_pwwd'

set :deploy_via, :remote_cache
set :use_sudo, false
ssh_options[:forward_agent] = true

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
end

namespace :deploy do  
  desc "Recreate symlink"
  task :resymlink, :roles => :app do
    run "#{try_sudo} rm -f #{current_path} && ln -s #{release_path} #{current_path}"
  end

end


require 'erb'

before "deploy:setup", :db
after "deploy:update_code", "db:symlink"

namespace :db do
  desc "Create database yaml in shared path"
  task :default do
    db_config = ERB.new <<-EOF
    base: &base
      adapter: mysql
      socket: /var/run/mysqld/mysql.sock
      username: #{mysql_user}
      password: #{mysql_password}

    development:
      database: #{app_name}_dev
      <<: *base

    test:
      database: #{app_name}_test
      <<: *base

    production:
      database: #{app_name}_prod
      <<: *base
    EOF

    run "#{try_sudo} mkdir -p #{shared_path}/config"
    put db_config.result, "#{shared_path}/config/database.yml"
  end

  desc "Make symlink for database yaml"
  task :symlink do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
end


after "deploy:create_symlink", "deploy:resymlink", "deploy:update_crontab"

每次我运行 cap deploy 我都会收到以下错误,之后部署停止并回滚。

*** [err :: ] rake aborted!
*** [err :: ] No such file or directory - /var/www/html/myapp.com/releases/20130224112516/config/database.yml
*** [err :: ] /var/www/html/myapp.com/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/application/configuration.rb:115:in `read'

请帮忙——我真的需要完成这件事。

4

1 回答 1

1

您需要写入文件而不仅仅是放入标准输出:

更改此行:

把 db_config.result, "#{shared_pa​​th}/config/database.yml"

File.open("#{shared_pa​​th}/config/database.yml", "w") { |f| f.puts db_config.result }

于 2013-02-24T17:40:35.673 回答