Bring the name of the workbench secret token config variable in line.
[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 # 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)
23   end
24 end
25
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.
30
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.
35
36 Dir.glob('*/generated/*') do |stale_file|
37   File.delete(stale_file)
38 end
39
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|
47
48       @count = 0
49       while @count < 10
50         @out = line.gsub!(/@@(.*?)@@/) do |var|
51           if config.key?(Regexp.last_match[1])
52             config[Regexp.last_match[1]]
53           else
54             var.gsub!(/@@/, '@_NOT_FOUND_@')
55           end
56         end
57         break if @out.nil?
58         @count += 1
59       end
60
61       output.write(line)
62     end
63   end
64   output.close
65 end