Capistrano符号链接数据库.yml任务错误



我正在运行一个带有Capistrano 2.12.0的Rails 3.2.x应用程序。我已经从github/版本控制中取出了我的database.yml,并手动将副本放在/home/deploy/myapp/shared/config/database.yml

我正在尝试让我的deploy.rb使用before:assets:precompile符号链接此文件,以便在发布目录中对该文件进行符号链接,并且部署可以继续。这是我得到的错误:

/Users/james/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/capistrano-2.12.0/lib/capistrano/configuration/callbacks.rb:103:in `on': please specify either a task name or a block to invoke (ArgumentError)

以下是我的deploy.rb的样子:

部署.rb

require "bundler/capistrano"
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
set :shared_children, shared_children + %w{public/uploads}
server "72.14.181.22", :web, :app, :db, primary: true
set :application, "myapp"
set :user, "deploy"
set :deploy_to, "/home/#{user}/#{application}"
#set :deploy_via, :remote_cache
set :use_sudo, false
set :rails_env, "production"

set :scm, "git"
set :repository, "git@github.com:james/#{application}.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
after "deploy:update"
before "deploy:assets:precompile", "config_symlink"
namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
  desc "reload the database with seed data"
  task :seed do
    run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}"
  end
end
task :config_symlink do
  run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end

基本上,我需要做的是在资产预编译之前将/home/deploy/myapp/shared/config/database.yml符号链接到/home/deloy/myapp/current/config/databasey.yml,以便访问数据库。

我确信我在这里有一些语法错误,但确实需要一些帮助。为了安全起见,我想让我的database.yml脱离版本控制,直接将其保留在myapp/shared/config中,并在部署时对其进行符号链接。

在最长的一段时间里,我以为我一直在做这件事,但显然我没有,所以我需要弄清楚。

非常感谢任何帮助,因为我不想求助于将database.yml保留在github/版本控制中。

我想我已经成功了。在我最初的deploy.rb中,我调用了after "deploy:update",但没有向回调传递任何信息,所以它对我造成了很大的影响。我已经清理了deploy.rb文件,并测试了到临时服务器的部署,它似乎可以工作。

deploy.rb更新

require "bundler/capistrano"
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
set :shared_children, shared_children + %w{public/uploads}
server "72.14.181.11", :web, :app, :db, primary: true
set :application, "myapp"
set :user, "deploy"
set :deploy_to, "/home/#{user}/#{application}"
#set :deploy_via, :remote_cache
set :use_sudo, false
set :rails_env, "production"

set :scm, "git"
set :repository, "git@github.com:james/#{application}.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true
before "deploy:assets:precompile", "config_symlink"
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
  task :start do ; end
  task :stop do ; end
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
  end
  desc "reload the database with seed data"
  task :seed do
    run "cd #{current_path}; bundle exec rake db:seed RAILS_ENV=#{rails_env}"
  end
end
task :config_symlink do
  run "ln -nfs #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
end

最新更新