summaryrefslogtreecommitdiff
path: root/bootstrap/pillar_config.rb
blob: 2a7ccbf34dcafc43a830cd4701f78251f37fa704 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/ruby

require 'digest'
require 'getoptlong'
require "json"
require 'socket'
require "yaml"

def sha()
    seed = ""
    File.open("/dev/urandom", "r") do |f|
        seed = "#{f.sysread(1024)}"
    end
    Digest::SHA256.hexdigest(seed)
end

def get_ip_address()
    ip_arr = Socket.ip_address_list.map { |addr|
        addr.ip_address
    }.reject { |addr|
        addr == "172.17.0.1" or addr.start_with?("127") or addr.include?("::")
    }
    if ip_arr.length == nil
        "127.0.0.1"
    else
        ip_arr[0]
    end
end

def process_yaml(branch)
    env_yaml_path = "#{File.dirname($0)}/config.yaml"
    if ! File.file?(env_yaml_path)
        STDERR.puts "Unable to find config.yaml. Exiting."
        exit(1)
    end
    components = [
        "admin-api-server",
        "customer-api-server",
        "admin-web-ui",
        "customer-web-ui",
        "job-scheduler-server",
        "workflow-server"
    ]
    yml = YAML.load_file(env_yaml_path)
    yml["baseimage"] = {}
    yml["baseimage"]["image_name"] = "openbook_baseimage"
    yml["baseimage"]["container_name"] = "baseimage"
    yml["baseimage"]["build_dir"] = "/root/openbook_build/baseimage"
    yml["database"] = {}
    yml["database"]["image_name"] = "openbook_database"
    yml["database"]["container_name"] = "database"
    yml["database"]["build_dir"] = "/root/openbook_build/database"
    yml["ansible"] = Hash.new
    yml["ansible"]["build_dir"] = "/root/openbook_build/ansible"
    components.each do |component|
        yml["#{component.gsub("-", "_")}"] = {
            "jar_name" => "#{component}-#{branch}",
            "image_name" => "openbook_#{component.gsub("-", "_")}_#{branch}",
            "container_name" => "#{component.gsub("-", "_")}_#{branch}",
            "build_dir" => "/root/openbook_build/#{component.gsub("-", "_")}"
        }
    end
    yml
end

def main()
    branch = ""
    opts = GetoptLong.new(["--branch", "-b", GetoptLong::REQUIRED_ARGUMENT])

    opts.each do |opt, arg|
        case opt
        when "--branch"
            branch = arg
		end
	end

    yml = process_yaml(branch)
    puts yml.to_json
end

main()
exit(0)