I'm trying to create a basic task for copying and linking database.yml file into my app, but I can't figure out why it s not working.
I'm using Capistrnao 3.1
This is my lib/capistrano/tasks/databases.cap file :
namespace :db_access do
# Idea : https://github.com/capistrano/sshkit/blob/master/EXAMPLES.md
desc 'Copy production database.yml from local workstation'
task :copy_production do
on roles :all do
execute :mkdir, '-p', "#{shared_path}/config"
upload! 'config/deploy/production.database.yml', "#{shared_path}/config/database.yml"
end
end
# Idea : http://stackoverflow.com/questions/9684649/capistrano-cant-deploy-my-database-yml
desc 'Create database.yml symlinks to current release'
task :create_symlinks do
on roles :all do
unless test "[ -f #{shared_path}/config/database.yml ]"
invoke 'db_access:copy_production'
end
execute :ln, "-nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
end
end
This is the ouput I got :
douglas@bilbo:/var/www/odpf$ cap production db_access:create_symlinks
DEBUG [3f670dfd] Running /usr/bin/env [ -f /var/www/odpf/shared/config/database.yml ] on myserver.net
DEBUG [3f670dfd] Command: [ -f /var/www/odpf/shared/config/database.yml ]
DEBUG [3f670dfd] Finished in 0.589 seconds with exit status 1 (failed).
cap aborted!
**undefined method `verbosity' for "/usr/bin/env db_access:copy_production\n":String**
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/formatters/pretty.rb:10:in `write'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/printer.rb:14:in `block in execute'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/printer.rb:13:in `tap'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/printer.rb:13:in `execute'
/var/www/odpf/lib/capistrano/tasks/databases.cap:20:in `block (3 levels) in <top (required)>'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => db_access:create_symlinks
I don't know how to invoke the other task. I inspirate myslef from https://github.com/capistrano/capistrano/blob/master/lib/capistrano/tasks/deploy.rake
If I try without the 'invoke' keyword and without ' ' signs :
namespace :db_access do
# Idea : https://github.com/capistrano/sshkit/blob/master/EXAMPLES.md
desc 'Copy production database.yml from local workstation'
task :copy_production do
on roles :all do
execute :mkdir, '-p', "#{shared_path}/config"
upload! 'config/deploy/production.database.yml', "#{shared_path}/config/database.yml"
end
end
# Idea : http://stackoverflow.com/questions/9684649/capistrano-cant-deploy-my-database-yml
desc 'Create database.yml symlinks to current release'
task :create_symlinks do
on roles :all do
unless test "[ -f #{shared_path}/config/database.yml ]"
db_access.copy_production
end
execute :ln, "-nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
end
end
The result is as follow :
douglas@bilbo:/var/www/odpf$ cap production db_access:create_symlinks --trace
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke db_access:create_symlinks (first_time)
** Execute db_access:create_symlinks
cap aborted!
undefined local variable or method `db_access' for #<SSHKit::Backend::Netssh:0x00000002862340>
/var/www/odpf/lib/capistrano/tasks/databases.cap:20:in `block (3 levels) in <top (required)>'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/backends/netssh.rb:54:in `run'
/home/douglas/.rvm/gems/ruby-2.1.0@rails3/gems/sshkit-1.3.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => db_access:create_symlinks
This must be a simple syntaxe mistake but since I can't find a guide that explain that I don't know how to do.
Thanks for your helps