要求Capistrano在链接(符号链接)文件之前运行任务

时间:2014-02-24 18:57:42

标签: ruby-on-rails-3 capistrano capistrano3

我一直在尝试写一个capistrano脚本,我将我的应用程序目录(support/config/#{rails_env})中的配置文件复制到capistrano中的shared directory(共享/配置)

rails_env => 'staging'

因此,当capistrano运行first time时,它会将文件从support/config/#{rails_env}目录复制到共享/ config目录,但是需要在文件通过capistrano链接之前运行它,即在此之前完成

set :linked_files, %w{config/api_config.yml}

以便链接的任务不会失败(因为它需要任务所需的文件存在于共享目录中)

这是我的Capfile(没什么好看的,因为大多数东西都是我的capistrno完成的)

set :application, 'custom-api'
set :repo_url, ''

# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :rails_env, 'staging' 
set :deploy_to, '/var/apps/staging/custom-api'
set :scm, :git

set :format, :pretty
set :log_level, :debug
set :rvm_type, :user   # Defaults to: :auto
set :rvm_ruby_version, 'ruby-1.9.3@484@custom-api'  
#set :rvm_custom_path, '~/.myveryownrvm'  # only needed if not detected
# set :pty, true
set :linked_files, %w{config/mongoid.yml config/api_config.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

#set :default_env, { path: "$HOME/.rvm/#{}:$PATH" }
set :keep_releases, 5
#SSHKit.config.command_map[:cp_r]  = "cp -r"

## Need to run before the file is linked
#before 'deploy:[task_name]' , 'deploy:copy_files'

namespace :deploy do
  desc 'Copy files from application to shared directory'
  ## copy the files to the shared directories
  task :copy_files do 
    on roles(:app) do
      execute :cp ,'-r',release_path.join('support/config'),shared_path
    end  
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      # Here we can do anything such as:
      # within release_path do
      #   execute :rake, 'cache:clear'
      # end
    end
  end
  after :finishing, 'deploy:cleanup'
end

我需要做的就是做

之类的事情

before 'deploy:[task_name]' , 'deploy:copy_files'

添加注意:使用Capistrno 3.0.1

1 个答案:

答案 0 :(得分:5)

根据他们的documentation,该任务称为 deploy:symlink:shared 。我会像你的例子那样装饰它:

before 'deploy:symlink:shared', 'deploy:copy_files'

当你装饰实际任务时要注意,每次调用任务时都会调用它。