Style improvements -- rubocop
[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') && (config[var].nil? || 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. Support up to 10 levels of nesting.
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
40       @count = 0
41       while @count < 10
42         @out = line.gsub!(/@@(.*?)@@/) do |var|
43           config[Regexp.last_match[1]] || var.gsub!(/@@/, '@_NOT_FOUND_@')
44         end
45         break if @out.nil?
46         @count += 1
47       end
48
49       output.write(line)
50     end
51   end
52   output.close
53 end