5 # Initialize config settings from config.yml
6 config = YAML.load_file('config.yml')
8 # ============================================================
9 # Add dynamically chosen config settings. These settings should
10 # be suitable for any installation.
12 # Any _PW/_SECRET config settings represent passwords/secrets. If they
13 # are blank, choose a password randomly.
14 config.each_key do |var|
15 if (var.end_with?('_PW') || var.end_with?('_SECRET')) && (config[var].nil? || config[var].empty?)
16 config[var] = rand(2**256).to_s(36)
20 # ============================================================
21 # For each *.in file in the docker directories, substitute any
22 # @@variables@@ found in the file with the appropriate config
23 # variable. Support up to 10 levels of nesting.
25 # TODO(twp): add the *.in files directory to the source tree, and
26 # when expanding them, add them to the "generated" directory with
27 # the same tree structure as in the original source. Then all
28 # the files can be added to the docker container with a single ADD.
30 Dir.glob('*/generated/*') do |stale_file|
31 File.delete(stale_file)
34 Dir.glob('*/*.in') do |template_file|
35 generated_dir = File.join(File.dirname(template_file), 'generated')
36 Dir.mkdir(generated_dir) unless Dir.exists? generated_dir
37 output_path = File.join(generated_dir, File.basename(template_file, '.in'))
38 output = File.open(output_path, "w")
39 File.open(template_file) do |input|
40 input.each_line do |line|
44 @out = line.gsub!(/@@(.*?)@@/) do |var|
45 if config.key?(Regexp.last_match[1])
46 config[Regexp.last_match[1]]
48 var.gsub!(/@@/, '@_NOT_FOUND_@')