From 649f0dd9c5ca586d8b637400dd19c0c4059447d6 Mon Sep 17 00:00:00 2001 From: Carlos Konstanski Date: Wed, 30 Aug 2017 13:09:56 -0600 Subject: initial commit --- bootstrap/pillar_config.rb | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 bootstrap/pillar_config.rb (limited to 'bootstrap/pillar_config.rb') diff --git a/bootstrap/pillar_config.rb b/bootstrap/pillar_config.rb new file mode 100755 index 0000000..60460b1 --- /dev/null +++ b/bootstrap/pillar_config.rb @@ -0,0 +1,84 @@ +#!/usr/bin/ruby + +require_relative 'http_client' +require 'digest' +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 get_jar_versions(yml) + ret = Hash.new + begin + http_client = HttpClient.new(url: yml["jars"]["url"], + username: yml["jars"]["username"], + password: yml["jars"]["password"]) + http_client.do_http(method: :propfind) + http_client.response.each_line do |line| + if line =~ /D:href.*\.jar/ + jar_name = line.chomp.split(/[<>]/)[2] + jarparts = jar_name.split(/\//) + name, *version_parts, junk1 = jarparts[jarparts.length - 1].split(".") + ret["#{name.gsub("-", "_")}"] = { + "jar_name" => jarparts[jarparts.length - 1], + "jar_version" => version_parts.join("."), + "image_name" => "openbook_#{name.gsub("-", "_")}", + "container_name" => "#{name.gsub("-", "_")}", + "build_dir" => "/root/openbook_build/#{name.gsub("-", "_")}" + } + end + end + rescue Exception => e + STDERR.puts "Error while contacting webdav endpoint: #{e.message}" + exit(1) + end + ret +end + +def process_yaml() + 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 + yml = YAML.load_file(env_yaml_path) + yml["baseimage"] = {} + yml["database"] = {} + yml["baseimage"]["image_name"] = "openbook_baseimage" + yml["baseimage"]["container_name"] = "baseimage" + yml["baseimage"]["build_dir"] = "/root/openbook_build/baseimage" + 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" + yml +end + +def main() + yml = process_yaml() + puts yml.merge(get_jar_versions(yml)).to_json +end + +main() +exit(0) -- cgit v1.3