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 # The APP_SECRET the application uses (with OMNIAUTH_APP_ID) to
13 # authenticate itself to Omniauth. By default this is generated
14 # randomly when the application is built; you can instead
15 # substitute a hardcoded string.
16 config['OMNIAUTH_APP_SECRET'] = rand(2**512).to_s(36)
18 # Any _PW/_SECRET config settings represent passwords/secrets. If they
19 # are blank, choose a password randomly.
20 config.each_key do |var|
21 if (var.end_with?('_PW') || var.end_with?('_SECRET')) && (config[var].nil? || config[var].empty?)
22 config[var] = rand(2**256).to_s(36)
26 # ============================================================
27 # For each *.in file in the docker directories, substitute any
28 # @@variables@@ found in the file with the appropriate config
29 # variable. Support up to 10 levels of nesting.
31 # TODO(twp): add the *.in files directory to the source tree, and
32 # when expanding them, add them to the "generated" directory with
33 # the same tree structure as in the original source. Then all
34 # the files can be added to the docker container with a single ADD.
36 Dir.glob('*/generated/*') do |stale_file|
37 File.delete(stale_file)
40 Dir.glob('*/*.in') do |template_file|
41 generated_dir = File.join(File.dirname(template_file), 'generated')
42 Dir.mkdir(generated_dir) unless Dir.exists? generated_dir
43 output_path = File.join(generated_dir, File.basename(template_file, '.in'))
44 output = File.open(output_path, "w")
45 File.open(template_file) do |input|
46 input.each_line do |line|
50 @out = line.gsub!(/@@(.*?)@@/) do |var|
51 if config.key?(Regexp.last_match[1])
52 config[Regexp.last_match[1]]
54 var.gsub!(/@@/, '@_NOT_FOUND_@')