当我尝试cap deploy:cold
时,一切都很好,但是在这个阶段:
** transaction: commit
* 2013-10-25 18:36:38 executing `deploy:migrate'
* executing "cd /home/test_app_deployer/apps/mini_reader/releases/20131025143548 && bundle exec rake RAILS_ENV=production db:migrate"
我有错误:
rake aborted!
** [out :: 81.218.92.235] FATAL: password authentication failed for user "test_app_deployer"
** [out :: 81.218.92.235] FATAL: password authentication failed for user "test_app_deployer"
** [out :: 81.218.92.235] /home/test_app_deployer/apps/mini_reader/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `initialize'
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell '1.9.3' -c 'cd /home/test_app_deployer/apps/mini_reader/releases/20131025143548 && bundle exec rake RAILS_ENV=production db:migrate'"
这是我的deploy.rb文件:
require "bundler/capistrano"
require "rvm/capistrano"
server "ip", :web, :app, :db, primary: true
set :application, "mini_reader"
set :domain, "reader.alma.by"
set :user, "test_app_deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :port, "222"
set :rvm_ruby_string, '1.9.3'
set :rails_env, "production"
set :scm, 'git'
set :repository, "git@github.com:user/app.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
namespace :imagemagick do
desc "Install the latest release of ImageMagick and the MagickWand Dev Library"
task :install, roles: :app do
run "#{sudo} apt-get -y update"
run "#{sudo} apt-get -y install imagemagick libmagickwand-dev"
end
after "deploy:install", "imagemagick:install"
end
在 /apps/app_name/shared/config 目录中cap deploy:setup
有database.yml文件之后。我用 postgres 创建了用户和数据库,并将其添加到这个文件(database.yml)中,它看起来像:
production:
adapter: postgresql
encoding: utf8
reconnect: false
database: reader_production
pool: 5
host: localhost
user: user_name
password: user_pass
更新
我已经从 git 存储库中删除了 database.example.yml 文件,并在deploy.rb文件中添加了一些说明:
before "deploy:setup", :db
after "deploy:update_code", "db:symlink"
namespace :db do
desc "create database.yml in shared dir"
task :default do
db_config = ERB.new <<-EOF
production:
adapter: postgresql
encoding: utf8
reconnect: false
database: db_production
pool: 5
host: localhost
user: username
password: pass
EOF
run "mkdir -p #{shared_path}/config"
put db_config.result, "#{shared_path}/config/database.yml"
end
我已经检查它是否在当前目录中使用正确的指令创建了 database.yml 文件,但我仍然有错误:
FATAL: password authentication failed for user "test_app_deployer
Why rails ignoring database.yml file?