#!/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["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)