Last active
January 18, 2016 09:52
-
-
Save carlcraig/377ed30bfa2015ea5049 to your computer and use it in GitHub Desktop.
Capistrano Symfony Parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "create empty parameters" | |
task :parameters_empty do | |
on roles(:all) do | |
if not test("[ -f #{shared_path}/app/config/parameters.yml ]") | |
upload! StringIO.new('---'), "#{shared_path}/app/config/parameters.yml" | |
end | |
end | |
end | |
desc "configure parameters with dist values if not defined" | |
task :parameters do | |
on roles(:all) do | |
distParameters = YAML::load(capture("cat #{release_path}/app/config/parameters.yml.dist")) | |
if test("[ -f #{shared_path}/app/config/parameters.yml ]") | |
parameters = YAML::load(capture("cat #{shared_path}/app/config/parameters.yml")) | |
if parameters | |
distParameters['parameters'].each do |k,v| | |
if parameters['parameters'][k].nil? && parameters['parameters'].fetch(k, false) == false | |
set :distParameter, ask(k, v) | |
parameters['parameters'][k] = fetch(:distParameter) | |
end | |
end | |
else | |
parameters = YAML::load(capture("cat #{release_path}/app/config/parameters.yml.dist")) | |
distParameters['parameters'].each do |k,v| | |
set :distParameter, ask(k, v) | |
parameters['parameters'][k] = fetch(:distParameter) | |
end | |
end | |
else | |
parameters = YAML::load(capture("cat #{release_path}/app/config/parameters.yml.dist")) | |
distParameters['parameters'].each do |k,v| | |
set :distParameter, ask(k, v) | |
parameters['parameters'][k] = fetch(:distParameter) | |
end | |
end | |
upload! StringIO.new(parameters.to_yaml), "#{shared_path}/app/config/parameters.yml" | |
end | |
end | |
desc "configure all parameters" | |
task :parameters_configure do | |
on roles(:all) do | |
distParameters = YAML::load(capture("cat #{release_path}/app/config/parameters.yml.dist")) | |
if test("[ -f #{shared_path}/app/config/parameters.yml ]") | |
parameters = YAML::load(capture("cat #{shared_path}/app/config/parameters.yml")) | |
if parameters | |
distParameters['parameters'].each do |k,v| | |
if parameters['parameters'][k].nil? && parameters['parameters'].fetch(k, false) == false | |
set :distParameter, ask(k, v) | |
parameters['parameters'][k] = fetch(:distParameter) | |
else | |
set :distParameter, ask(k, parameters['parameters'][k]) | |
parameters['parameters'][k] = fetch(:distParameter) | |
end | |
end | |
else | |
parameters = YAML::load(capture("cat #{release_path}/app/config/parameters.yml.dist")) | |
distParameters['parameters'].each do |k,v| | |
set :distParameter, ask(k, v) | |
parameters['parameters'][k] = fetch(:distParameter) | |
end | |
end | |
else | |
parameters = YAML::load(capture("cat #{release_path}/app/config/parameters.yml.dist")) | |
distParameters['parameters'].each do |k,v| | |
set :distParameter, ask(k, v) | |
parameters['parameters'][k] = fetch(:distParameter) | |
end | |
end | |
upload! StringIO.new(parameters.to_yaml), "#{shared_path}/app/config/parameters.yml" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, @carlcraig! That's exactly what I was looking for.
Maybe parameters.yml should not be copied to a shared folder? Each release could have different set of parameters.