Specify all configuration settings in config.yml.
[arvados.git] / docker / config.rb
1 #! /usr/bin/env ruby
2
3 require 'yaml'
4
5 # Initialize config settings from config.yml
6 config = YAML.load_file('config.yml')
7
8 # ============================================================
9 # Add dynamically chosen config settings. These settings should
10 # be suitable for any installation.
11
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)
17
18 # The secret token in services/api/config/initializers/secret_token.rb.
19 config['API_SECRET'] = rand(2**256).to_s(36)
20
21 # Any _PW config settings represent a database password.  If it
22 # is blank, choose a password randomly.
23 config.each_key do |var|
24   if var.end_with?('_PW') and (config[var].nil? or config[var].empty?)
25     config[var] = rand(2**256).to_s(36)
26   end
27 end
28
29 # ============================================================
30 # For each *.in file in the docker directories, substitute any
31 # @@variables@@ found in the file with the appropriate config
32 # variable.
33
34 Dir.glob('*/*.in') do |template_file|
35   output_path = template_file.sub(/\.in$/, '')
36   output = File.open(output_path, "w")
37   File.open(template_file) do |input|
38     input.each_line do |line|
39       output.write(line.gsub(/@@(.*?)@@/) { |var| config[$1] || var })
40     end
41   end
42   output.close
43 end