1

First of all I've never used ruby and capifony so this question might be very easy for some of you but not for me. I tried to find examples related to my question but couldn't find any or I'm too new to ruby to miss!

When deploying my Symfony app, the value of a particular key in my parameters file should be dynamically appended so, rather than using exact generic value coming from distribution file below:

parameters_prod.yml.dist

parameters:
   my_prefix: my_value_prefix_

Straight after deployment, parameters.yml should read like below:

parameters.yml

parameters:
   my_prefix: my_value_prefix_8235647895

8235647895 part above is going to be timestamp.

How can I do this?

My current deploy.rb

namespace :mytest do
  desc "Upload the parameters.yml"
  task :upload_parameters do

    origin_file = parameters_dir + "/" + parameters_file if parameters_dir && parameters_file
    origin_file_append = parameters_dir + "/" + parameters_file_append if parameters_dir && parameters_file_append

    if origin_file && File.exists?(origin_file)
      relative_path = "app/config/parameters.yml"

      files = [origin_file]
      files << origin_file_append if origin_file_append && File.exists?(origin_file_append)

      tmp_origin_file = origin_file + '.tmp'

      File.open(tmp_origin_file, 'w') do |fo|
        files.each do |file|
          File.foreach(file) do |li|
            fo.puts li
          end
        end
      end

      if shared_files && shared_files.include?(relative_path)
        destination_file = shared_path + "/" + relative_path
      else
        destination_file = latest_release + "/" + relative_path
      end
      try_sudo "mkdir -p #{File.dirname(destination_file)}"

      top.upload(tmp_origin_file, destination_file)

      File.delete(tmp_origin_file)
    end
  end
end
BentCoder
  • 12,257
  • 22
  • 93
  • 165
  • excuse me the question but, what do you need to do with this parameters? – Matteo Aug 06 '15 at 13:19
  • When parameters.yml is created from parameters_prod.yml.dist with composer install, newly generated parameters.yml should have `my_prefix: my_value_prefix_8235647895` instead of just `my_prefix: my_value_prefix_` – BentCoder Aug 06 '15 at 13:25
  • of course, i suggest you to act in a similar manner but injecting the value by the container in same manner. I [use](http://blog.lavoie.sl/2012/10/automatic-cache-busting-using-git-in-symfony2.html) this approach to change the assets version. You can do a similar thing for inject a parameter i suppose. hope this help – Matteo Aug 06 '15 at 13:36

0 Answers0