/
gencfg.rb
executable file
·40 lines (32 loc) · 1.29 KB
/
gencfg.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/ruby
require 'optparse'
require 'ostruct'
require 'erb'
require 'yaml'
require 'base64'
options = OpenStruct.new
OptionParser.new do |opt|
opt.on('-e', '--environment ENVIRONMENT', 'the environment to make the deploy (see app.yaml)') { |o| options.env = o }
end.parse!
raise OptionParser::MissingArgument.new('-e is required') if options.env.nil?
config = YAML.load_file('app.yaml')
unless config['environments'].has_key?(options.env)
raise KeyError.new("There is no such environment called '#{options.env}' in the YAML configuration file")
end
temp_dir = './tmp'
Dir.mkdir(temp_dir) unless File.exists?(temp_dir)
File.open("#{temp_dir}/nginx.conf", 'w') do |f|
renderer = ERB.new(File.read('templates/nginx.conf.erb'), 0, '>')
f.write(renderer.result(binding))
end
File.open("#{temp_dir}/Dockerfile", 'w') do |f|
renderer = ERB.new(File.read('templates/Dockerfile.erb'), 0, '>')
f.write(renderer.result(binding))
end
user = config['environments'][options.env]['rabbitmq']['user']
password = config['environments'][options.env]['rabbitmq']['password']
basic_auth = Base64.strict_encode64("#{user}:#{password}")
File.open("#{temp_dir}/default.conf", 'w') do |f|
renderer = ERB.new(File.read('templates/default.conf.erb'), 0, '>')
f.write(renderer.result(binding))
end