2014-02-24 45 views
3

我一直在尝试编写capistrano脚本,其中我的应用程序目录(support/config/#{rails_env})的复制配置文件为capistrano的shared directory(共享/配置)Ask Capistrano在链接(符号链接)文件之前运行任务

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, '[email protected]@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'

新增注:我们ING Capistrno 3.0.1

回答

5

根据他们documentation,任务被称为部署:符号链接:共享。我会装点,像你的例子:

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

要知道,当你装点实际任务一样,它会被称为每一个任务被调用时。

+0

刚发现文档相当全面谢谢 – Ratatouille