# To run devops you can use command
# `bundle exec thin -R $devops_home/config.ru -e $env -d -p $port -t 600 -u $user --pid $pid_file --log $log_file start`
require "rubygems"
require "bundler/setup"
require 'byebug'

root = File.dirname(__FILE__)
$:.push root

require_relative "core/devops-service"
require_relative "core/devops-config"
require_relative "core/devops-routes"

# Read configuration file
DevopsConfig.read
config = DevopsConfig.config

puts "Devops home: #{config[:devops_dir]}"
unless File.exists?(config[:devops_dir])
  FileUtils.mkdir_p config[:devops_dir]
  puts "Directory '#{config[:devops_dir]}' has been created"
end

[:report_dir_v2, :project_info_dir].each do |key|
  directory = config[key]
  FileUtils.mkdir_p(directory) unless File.exists?(directory)
end

DevopsService.init
if Devops::Routes.routes.empty?
  puts "No applications"
  exit -1
end

require "providers/static"
require "providers/aws"

Devops::Routes.routes.each do |p, c|
  map(p) do
    run c
  end
end

