Git 针对不同环境的不同操作

Git 针对不同环境的不同操作,git,capistrano,capistrano3,Git,Capistrano,Capistrano3,快速回答第三个问题 我正在使用Capistrano将CMS部署到登台环境,然后部署到生产环境 我需要上传一个配置文件,其中包含git repo之外的CMS的数据库信息 有两个配置文件staging config和production config 如何让Capistrano根据目标上传文件或执行任务 task :upload_config do on roles(:all) do |host| within fetch(:shared_path) do

快速回答第三个问题

我正在使用Capistrano将CMS部署到登台环境,然后部署到生产环境

我需要上传一个配置文件,其中包含git repo之外的CMS的数据库信息

有两个配置文件staging config和production config

如何让Capistrano根据目标上传文件或执行任务

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 

您始终可以按如下方式使用
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 

太棒了,我不知道的是:stage变量的存在