我使用NGINX和Passenger为我的staging环境设置了一个服务器。 我还设置了一个staging.rb文件,它是在environments下的production.rb文件的副本。 在我的database.yml文件中,我添加了一个staging配置:
staging:
adapter: mysql2
database: myapp_staging
username: root
password: xxxxxxxxxxxxx
port: 3306
pool: 15
timeout: 5000
Environments/staging.rb:
role :app, %w{deploy@111.111.111.111}
role :web, %w{deploy@111.111.111.111}
role :db, %w{deploy@111.111.111.111}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server definition into the
# server list. The second argument is a, or duck-types, Hash and is
# used to set extended properties on the server.
server '111.111.111.111', user: 'deploy', roles: %w{web app db}, port: 0001
我使用
cap staging deploy
进行部署,但应用程序无法启动,在日志中显示:Unknown database 'myapp_production'
。
我该如何强制它使用staging数据库?
编辑
Deploy.rb:
set :application, 'dispatch'
set :repo_url, 'myapp'
set :deploy_to, '/home/deploy/myapp'
set :scm, :git
set :branch, 'master'
set :keep_releases, 5
set :format, :pretty
set :log_level, :debug
set :pty, true
set :passenger_restart_with_sudo, true
set :stages, ["staging", "production"]
set :default_stage, "staging"
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :rvm_map_bins, fetch(:rvm_map_bins, []).push('rvmsudo')
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
config/database.yml
文件,它指向了myapp_production
数据库。请参考 http://capistranorb.com/documentation/getting-started/preparing-your-application/ 中的2. Move secrets out of the repository.
部分,了解如何在使用 capistrano 部署时处理 database.yml。基本上,你需要在各自的服务器上保留一个 staging/production 版本的文件,并在部署时将其复制到所需位置。 - Prakash Murthy