Add prerequisites for Keep server described in
[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 config['WORKER_SECRET'] = rand(2**256).to_s(36)
21
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)
27   end
28 end
29
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.
34
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.
39
40 Dir.glob('*/generated/*') do |stale_file|
41   File.delete(stale_file)
42 end
43
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|
51
52       @count = 0
53       while @count < 10
54         @out = line.gsub!(/@@(.*?)@@/) do |var|
55           if config.key?(Regexp.last_match[1])
56             config[Regexp.last_match[1]]
57           else
58             var.gsub!(/@@/, '@_NOT_FOUND_@')
59           end
60         end
61         break if @out.nil?
62         @count += 1
63       end
64
65       output.write(line)
66     end
67   end
68   output.close
69 end