capistrano与database.yml部署错误
问题描述:
我想部署使用capistrano但是我不断收到此database.yml未找到错误。我的database.yml文件没有被提交到我的仓库,我试图设置我的deploy.rb文件来动态创建database.yml,但它似乎没有工作。这里是我的deploy.rb文件:capistrano与database.yml部署错误
require "bundler/capistrano"
set :application, "myapp.com"
set :app_name, "myapp"
set :repository, "[email protected]: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"
每次我跑帽部署我碰到下面的错误之后,部署停止并回滚。
*** [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'
请帮助 - 我真的需要完成这件事。
答
你需要写一个文件不仅提出到stdout:
改变这一行:
放db_config.result, “#{} shared_path /config/database.yml”
到
File.open(“#{shared_path} /config/database.yml”,“w”){| f | f.puts db_config.result}