1

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 
4

1 回答 1

1

您始终可以if..elseif..end按如下方式使用:

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

或者,如果您只有暂存和生产:

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 
于 2014-01-29T22:58:03.717 回答