ruby - Capistrano cap production deploy fails on migration but cap production deploy:migrate passes -
i've come across strange problem capistrano while getting production server ready. when run cap production deploy
, fails on deploy:migrate step
activerecord::adapternotspecified: 'production' database not configured. available: ["defaul…
yet, when run cap production deploy:migrate
, capistrano completes successfully.
on actual server, able run rails_env=production bundle exec rake:migrate
without problems either.
the capistrano log spits out same command both:
[deploy:migrate] run
rake db:migrate
my database config looks this:
production: adapter: mysql2 encoding: utf8 database: foo host: localhost pool: 5 timeout: 5000 username: bar password: password socket: /opt/bitnami/mysql/tmp/mysql.sock
i should mention have set rails env in deploy.rb so: set :rails_env, :production
here relevent information in gemfile:
gem 'mysql2', '~> 0.4.5' group :development gem 'capistrano', '~> 3.6', '>= 3.6.1' gem 'capistrano-rvm' gem 'capistrano-bundler' gem 'capistrano-rails' gem 'capistrano-passenger' end
can shed light on missing here? new capistrano.
after lot of searching found root cause.
i didn't realise "current" directory (or symlink fair) created @ end of capistrano process , since had earlier trial run rake_env=development, had current symlink on server.
before deploy:migrate step, upload database.yml secure location server via custom task uses command:
upload! "#{secure_data}database.yml", "#{current_path}/config/"
which @ time of before deploy:migrate, confusion, thought rake db:migrate being run current symlink, in fact being run latest release directory. latest release directory did not have production database information file uploaded current symlink pointed old release.
all in all, custom task caused problem , if else comes across similar scenario, command instead:
upload! "#{secure_data}database.yml", "#{release_path}/config/"
the key being release_path
variable instead of current_path
variable.
Comments
Post a Comment