Capistrano的 - 不能部署我的database.yml
当我尝试部署我与Capistrano的应用程序,我会得到这个错误:Capistrano的 - 不能部署我的database.yml
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
database: my_db
pool: 15
username: my_user_name
password: my_pass
host: localhost
在
/confing
/部署是文件的 “生产”, “分期”
我在这里错过了什么/我应该在哪里寻找失败?服务器上的数据库凭据应该是正确的。
编辑 - 这里是我的部署
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
问题:
cp: cannot stat `/var/www/my_app/releases/20120313144907/config/database.staging.yml': No such file or directory
我不知道如何解决你的问题。它看起来像database.staging.yml没有被部署,所以没有什么可以复制。
但我认为这有一个更好的工作流程。像设置和数据库配置之类的事情通常不会在部署之间发生变化,所以这些事情可以在所有Capistrano版本的共享文件夹中进行。通常情况下,你不希望你的database.yml在你的repo中,因为它是敏感信息。您可以通过在您的.gitignore
中排除config/database.yml
来满足这两个要求。
这需要您在服务器上设置一次。您需要创建一个database.yml
在your_app_path/shared/config
。共享是当前和发布的兄弟。
您的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
这意味着你的回购不包含任何database.yml
文件。因为他们可能已经在你的回购。你必须要git rm
他们,提交。将它们添加到.gitignore
并确认。
我们这样做了,但在config中包含了一个database.yml.example,开发人员可以使用它在本地进行本地化,而无需猜测database.yml设置 – tehfoo 2013-03-01 23:47:05
我认为current/config/database.yml是链接到shared/config/database.yml如果shared/config/database.yml丢失,它会给你'没有这样的文件或目录'。我们可以手动创建它到shared/config/database.yml并进行部署。这东西在这里工作。 – vajapravin 2013-04-02 07:48:14
对不起,你的'deploy.rb'脚本为什么提到'settings.yml'? – Matthias 2016-03-06 00:10:51
在Capistrano的3设置config.assets.initialize_on_precompile
到false
OK,链接文件是内置。约翰的回答很简单:
- 在
shared/
文件夹中创建config/database.yml
-
在
config/deploy.rb
使用此行set :linked_files, fetch(:linked_files, []).push('config/database.yml')
这不会有什么约翰说。
就是这样。谢谢 – Francisco 2016-08-11 22:58:45
我们如何解决最新版本3.8.0的问题? – 2017-03-20 12:41:13
当您在该机器上手动运行cp命令时会发生什么情况? – 2012-03-13 13:18:13
.yml或.ymp?如果你的.ymp文件被错误地命名为 – DGM 2012-03-13 13:19:45
.yml,我的不好... – user984621 2012-03-13 13:25:22