我正在尝试使用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'
请帮忙 - 我真的需要完成这件事。
答案 0 :(得分:1)
你需要写一个文件而不只是写入stdout:
更改此行:
put db_config.result,“#{shared_path} /config/database.yml”
到
File.open(“#{shared_path} /config/database.yml”,“w”){| f | f.puts db_config.result}