Capistrano - 不能部署我的database.yml [英] Capistrano - can't deploy my database.yml
问题描述
当我尝试使用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
我的 database.yml 即为空, database.staging.yml
production:
adapter:mysql2
encoding:utf8
reconnect:false
数据库:my_db
池:15
用户名:my_user_name
密码:my_pass
host:localhost
在 / confing / deploy 中是文件productionstaging
缺少这里/我应该在哪里寻找失败?
EDIT - 这里是我的部署
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 b $ b set:deploy_via,:remote_cache
#set:keep_releases,1
set:rails_env,'production'
role:web,domain
角色:app,domain
角色:db,domain,:primary => true#这是Rails迁移将运行
命名空间:deploy do
任务:build_gems,:roles => :app do
descBuilding gems
runcd#{release_path}& bundle install --deployment
end
task:migrations do
desc迁移数据库
runcd#{release_path}& rake db:migrate RAILS_ENV = production
end
[:start,: stop] .each do | t |
desc#{t}任务是与乘客的空操作
task t,:roles => :app do; end
end
desc使用restart.txt重新启动乘客
task:restart,:roles => :app,:except => {:no_release =>在deploy:update_code,deploy:build_gems,db:b之后运行truedo
运行touch#{release_path} /tmp/restart.txt
end
在deploy:update,bluepill:copy_config,bluepill:restart之后的copy_configuration,config:copy,deploy:migrations,deploy:cleanup
end $ b b
namespace:db do
task:copy_configuration do
runcp#{release_path} /config/database.staging.yml#{release_path} /config/database.yml
end
end
命名空间:config do
任务:copy do
运行cp#{release_path} /config/config.staging.yml#{release_path} /config/config.yml
end
end
命名空间:bluepill do
desc重新启动bluepill进程
任务:restart,:roles = > [:app] do
run#{release_path} / script / delayed_job stop
sudo/etc/init.d/bluepill.sh restart
end
#desc加载bluepill配置并启动它
## task:start,:roles => [:app] do
#sudo/etc/init.d/bluepill.sh start
#end
desc打印bluepills监控的进程状态
task:status,:roles => [:app] do
sudobluepill status
end
$ b desc复制配置
task:copy_config,:roles => [:app] do
运行cp#{release_path} /config/bluepill/configuration.rb /srv/script/bluepill.rb
end
end
问题:
cp :can not stat`/var/www/my_app/releases/20120313144907/config/database.staging.yml':没有这样的文件或目录
解决方案我不知道如何解决你的问题。看起来database.staging.yml没有被部署,所以没有什么可以复制。
我认为有一个更好的工作流,虽然。设置和数据库配置等设置通常不会在部署之间进行更改,因此这些内容可以在所有capistrano版本的共享文件夹中。通常,您不希望您的database.yml在您的repo中,因为它是敏感的信息。您可以通过排除
.gitignore
中的config / database.yml
来满足这两个要求。
这需要您在服务器上进行一次设置。您需要在
your_app_path / shared / config
中创建database.yml
。共享是当前和发布的兄弟。
您的
deploy.rb
应该有一个任务, release的database.yml
到共享目录中的on。像这样:之前的deploy:assets:precompiledo
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
并提交。When I try to deploy my app with capistrano, I'll get this error:
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
My database.yml ie empty, 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"
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
解决方案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.
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
.This requires you to do a one time set up on your servers. You need create a
database.yml
atyour_app_path/shared/config
. Shared is a sibling to current and releases.Your
deploy.rb
should have a task that symlinks the newly deployed release'sdatabase.yml
to the on in the shared directory. Like this: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 togit rm
them, commit. Add them to the.gitignore
and commit that.这篇关于Capistrano - 不能部署我的database.yml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!