Skip to content

Instantly share code, notes, and snippets.

@jakzal
Created October 25, 2011 11:41
Show Gist options
  • Save jakzal/1312418 to your computer and use it in GitHub Desktop.
Save jakzal/1312418 to your computer and use it in GitHub Desktop.
parameters.yml configuration during capifony deployment for Symfony2
set :shared_files, [app_path + "/config/parameters.yml"]
namespace :symfony do
namespace :configure do
def shared_parameters_path
"#{shared_path}/#{app_path}/config/parameters.yml"
end
def app_parameters_path
"#{latest_release}/#{app_path}/config/parameters.yml"
end
def shared_parameters_config
@shared_parameters_config ||= fetch_yaml "#{shared_parameters_path}"
end
def app_parameters_config
@app_parameters_config ||= fetch_yaml "#{app_parameters_path}"
end
def fetch_yaml (yaml_path)
require 'yaml'
file = capture("cat #{yaml_path}")
YAML::load(file)
end
task :parameters do
conf_files_exists = capture("if test -s #{shared_parameters_path} ; then echo 'exists' ; fi").strip
conf_file_changed = false
if !conf_files_exists.eql?("exists")
run "mkdir -p #{shared_path}/#{app_path}/config"
run "cp #{app_parameters_path} #{shared_parameters_path}"
shared_parameters_config['parameters'].sort.map do |key, value|
prompt_with_default(:"#{key}", app_config_parameters.fetch(:"#{key}", value))
shared_parameters_config['parameters'][key] = eval key;
end
conf_file_changed = true
end
app_parameters_config['parameters'].sort.map do |key, value|
if !shared_parameters_config['parameters'].has_key?(key)
prompt_with_default(:"#{key}", app_config_parameters.fetch(:"#{key}", value))
shared_parameters_config['parameters'][key] = eval key;
conf_file_changed = true
end
end
if conf_file_changed
put shared_parameters_config.to_yaml, "#{shared_parameters_path}"
end
end
end
end
before "deploy:finalize_update" do
symfony.configure.parameters
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment