문제

Quick Capistrano 3 question.

I am using Capistrano to deploy a CMS to a staging environment and then to production.

I need to upload a configuration file with database info with the CMS that lives outside of the git repo.

There are two config files staging-config and production-config.

How can I get Capistrano to upload a file or execute a task based on the target?

task :upload_config do
    on roles(:all) do |host|
        within fetch(:shared_path) do
            upload! 'staging-config.php', "#{fetch :shared_path}/staging-config.php"
        end
    end
end 
도움이 되었습니까?

해결책

You can always use if..elseif..end as follows:

if fetch(:stage) == :production
...
elsif fetch(:stage) == :staging
...
end

Or, if you have staging and production only:

task :upload_config do
    on roles(:all) do |host|
        within fetch(:shared_path) do
            upload! "#{fetch(:stage).to_s}-config.php", "#{fetch :shared_path}/#{fetch(:stage).to_s}-config.php"
        end
    end
end 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top