Skip to content

Instantly share code, notes, and snippets.

@juliendufresne
Created September 29, 2016 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliendufresne/498077881f7a8ce2c302f9339dcabe5b to your computer and use it in GitHub Desktop.
Save juliendufresne/498077881f7a8ce2c302f9339dcabe5b to your computer and use it in GitHub Desktop.
Capistrano task - checks parameters.yml keys against parameters.yml.dist
namespace :symfony do
desc "Check if shared parameters.yml is in sync with release parameters.yml.dist"
task :check_parameters, :except => { :no_release => true } do
puts "--> <symfony:check_parameters>"
distParameters = YAML::load(capture("cat #{release_path}/app/config/parameters.yml.dist"))
invoke_command("if [ -f '#{shared_path}/app/config/parameters.yml' ]; then echo -n 'true'; else echo -n 'false'; fi") do |ch, stream, out|
if out != 'true'
puts " \e[31mUnable to find file #{shared_path}/app/config/\e[35mparameters.yml\e[0m"
exit 1
end
end
invoke_command("cat #{shared_path}/app/config/parameters.yml") do |ch, stream, out|
parameters = YAML::load(out)
if !parameters.kind_of?(Hash) || !parameters.key?('parameters') || !parameters['parameters'].kind_of?(Hash)
puts " \e[31mFile \e[1m#{shared_path}/app/config/parameters.yml\e[22m must contains a \e[1mparameters\e[22m key which itself should be an Hash\e[0m"
puts " \e[31mIs it a valid yaml file ?\e[0m"
exit 1
end
distParameters['parameters'].each do |k,v|
if parameters['parameters'][k].nil? && parameters['parameters'].fetch(k, false) == false
puts " \e[31mParameters \e[1m#{k}\e[22m is missing in the file \e[1m#{shared_path}/app/config/\parameters.yml\e[22m\e[0m"
exit 1
end
end
end
puts "--> </symfony:check_parameters>"
end
end
@juliendufresne
Copy link
Author

We need to check if all the keys defined in app/config/parameters.yml.dist (which is versioned) are defined in the shared/app/config/parameters.yml of every server.

This will tell us if we have forget to define some new keys in our production/staging server

@juliendufresne
Copy link
Author

Call this after shared_file:symlink

after "shared_file:symlink" do
    symfony.check_parameters
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment