質問

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