<commit_before>require "/opt/engines/lib/ruby/containers/ManagedContainer.rb"
require "/opt/engines/lib/ruby/containers/ManagedContainerObjects.rb"
require "/opt/engines/lib/ruby/containers/ManagedEngine.rb"
require "/opt/engines/lib/ruby/ManagedServices.rb"
require "/opt/engines/lib/ruby/system/SysConfig.rb"
require "rubygems"
require "git"
require 'fileutils'
require 'json'

require_relative 'builder_public.rb'
require_relative 'BluePrintReader.rb'
require_relative 'DockerFileBuilder.rb'
require_relative 'SystemAccess.rb'


require_relative 'build_report.rb'
include BuildReport

require_relative 'templating.rb'
include Templating

class EngineBuilder
  @repoName=nil
  @hostname=nil
  @domain_name=nil
  @build_name=nil
  @web_protocol="HTTPS and HTTP"

  attr_reader :last_error,
  :repoName,
  :hostname,
  :domain_name,
  :build_name,
  :set_environments,
  :container_name,
  :environments,
  :runtime,
  :webPort,
  :http_protocol,
  :blueprint,
  :first_build
  class BuildError < StandardError
    attr_reader :parent_exception,:method_name
    def initialize(parent,method_name)
      @parent_exception = parent
    end

  end

  def initialize(params,core_api)
    @container_name = params[:engine_name]
    @domain_name = params[:domain_name]
    @hostname = params[:host_name]
    custom_env= params[:software_environment_variables]
    #   custom_env=params
    @core_api = core_api
    @http_protocol = params[:http_protocol]
    p params
    @memory = params[:memory]
    @repoName= params[:repository_url]
    @cron_job_list = Array.new
    @build_name = File.basename(@repoName).sub(/\.git$/,"")
    @workerPorts=Array.new
    @webPort=8000
    @vols=Array.new
    @first_build = true

    @attached_services = Array.new
    
    @builder_public = BuilderPublic.new(self)
    @system_access = SystemAccess.new()
    p :custom_env
    p custom_env

    if custom_env == nil
      @set_environments = Hash.new
      @environments = Array.new
    elsif  custom_env.instance_of?(Array) == true
      @environments = custom_env # happens on rebuild as custom env is saved in env on disk
      #FIXME need to vet all environment variables
      @set_environments = Hash.new
    else
      env_array = custom_env.values
      custom_env_hash = Hash.new

      env_array.each do |env_hash|
        p :env_hash
        p env_hash

        if env_hash != nil && env_hash[:name] !=nil && env_hash[:value] != nil
          env_hash[:name] = env_hash[:name].sub(/_/,"")
          custom_env_hash.store(env_hash[:name],env_hash[:value])
        end
      end
      p :Merged_custom_env
      p custom_env_hash
      @set_environments =  custom_env_hash
      @environments = Array.new<commit_msg>custom_envs<commit_after>require "/opt/engines/lib/ruby/containers/ManagedContainer.rb"
require "/opt/engines/lib/ruby/containers/ManagedContainerObjects.rb"
require "/opt/engines/lib/ruby/containers/ManagedEngine.rb"
require "/opt/engines/lib/ruby/ManagedServices.rb"
require "/opt/engines/lib/ruby/system/SysConfig.rb"
require "rubygems"
require "git"
require 'fileutils'
require 'json'

require_relative 'builder_public.rb'
require_relative 'BluePrintReader.rb'
require_relative 'DockerFileBuilder.rb'
require_relative 'SystemAccess.rb'


require_relative 'build_report.rb'
include BuildReport

require_relative 'templating.rb'
include Templating

class EngineBuilder
  @repoName=nil
  @hostname=nil
  @domain_name=nil
  @build_name=nil
  @web_protocol="HTTPS and HTTP"

  attr_reader :last_error,
  :repoName,
  :hostname,
  :domain_name,
  :build_name,
  :set_environments,
  :container_name,
  :environments,
  :runtime,
  :webPort,
  :http_protocol,
  :blueprint,
  :first_build
  class BuildError < StandardError
    attr_reader :parent_exception,:method_name
    def initialize(parent,method_name)
      @parent_exception = parent
    end

  end

  def initialize(params,core_api)
    @container_name = params[:engine_name]
    @domain_name = params[:domain_name]
    @hostname = params[:host_name]
    custom_env= params[:software_environment_variables]
    #   custom_env=params
    @core_api = core_api
    @http_protocol = params[:http_protocol]
    p params
    @memory = params[:memory]
    @repoName= params[:repository_url]
    @cron_job_list = Array.new
    @build_name = File.basename(@repoName).sub(/\.git$/,"")
    @workerPorts=Array.new
    @webPort=8000
    @vols=Array.new
    @first_build = true

    @attached_services = Array.new
    
    @builder_public = BuilderPublic.new(self)
    @system_access = SystemAccess.new()
    p :custom_env
    p custom_env

    if custom_env == nil
      @set_environments = Hash.new
      @environments = Array.new
    elsif  custom_env.instance_of?(Array) == true
      @environments = custom_env # happens on rebuild as custom env is saved in env on disk
      #FIXME need to vet all environment variables
      @set_environments = Hash.new
    else
#      env_array = custom_env.fall
      custom_env_hash = custom_env
#      env_array.each do |env_hash|
#        p :env_hash
#        p env_hash
#
#        if env_hash != nil && env_hash[:name] !=nil && env_hash[:value] != nil
#          env_hash[:name] = env_hash[:name].sub(/_/,"")
#          custom_env_hash.store(env_hash[:name],env_hash[:value])
#        end
      end
      p :Merged_custom_env
      p custom_env_hash
      @set_environments =  custom_env_hash
      @environments = Array.new
{'fraction_non_alphanumeric': 0.10475839173736629, 'fraction_numerical': 0.0014754703061600886, 'mean_word_length': 3.7279860505666957, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2353041', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1785, 'n_words': 345}