3

support/config/#{rails_env}私は自分のアプリケーションディレクトリ( )からカピストラーノのshared directory(共有/構成 )に設定ファイルをコピーしたカピストラーノスクリプトを書き込もうとしています

rails_env => 'staging'

そのため、カピストラーノを実行するfirst timeと、ファイルがsupport/config/#{rails_env}ディレクトリから共有/構成ディレクトリにコピーされますが、ファイルがカピストラーノによってリンクされる前、つまりこれが完了する前に実行する必要があります

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 の使用

4

1 に答える 1

7

彼らのドキュメントによると、タスクはdeploy:symlink:sharedと呼ばれています。あなたの例のように飾ります:

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

そのタスクが呼び出されるたびに呼び出されるように実際のタスクを装飾する場合は注意してください。

于 2014-02-24T22:01:17.217 に答える