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 # The secret token in services/api/config/initializers/secret_token.rb.
19 config['API_SECRET'] = rand(2**256).to_s(36)
20 config['WORKER_SECRET'] = rand(2**256).to_s(36)
22 # Any _PW config settings represent a database password. If it
23 # is blank, choose a password randomly.
24 config.each_key do |var|
25 if var.end_with?('_PW') && (config[var].nil? || config[var].empty?)
26 config[var] = rand(2**256).to_s(36)
30 # ============================================================
31 # For each *.in file in the docker directories, substitute any
32 # @@variables@@ found in the file with the appropriate config
33 # variable. Support up to 10 levels of nesting.
35 # TODO(twp): add the *.in files directory to the source tree, and
36 # when expanding them, add them to the "generated" directory with
37 # the same tree structure as in the original source. Then all
38 # the files can be added to the docker container with a single ADD.
40 Dir.glob('*/generated/*') do |stale_file|
41 File.delete(stale_file)
44 Dir.glob('*/*.in') do |template_file|
45 generated_dir = File.join(File.dirname(template_file), 'generated')
46 Dir.mkdir(generated_dir) unless Dir.exists? generated_dir
47 output_path = File.join(generated_dir, File.basename(template_file, '.in'))
48 output = File.open(output_path, "w")
49 File.open(template_file) do |input|
50 input.each_line do |line|
54 @out = line.gsub!(/@@(.*?)@@/) do |var|
55 if config.key?(Regexp.last_match[1])
56 config[Regexp.last_match[1]]
58 var.gsub!(/@@/, '@_NOT_FOUND_@')