Provisoning upgades

This commit is contained in:
CHIEFSOFT\ameye
2025-01-19 20:16:22 -05:00
parent f4d1b12c5b
commit 657b26c548
4 changed files with 42 additions and 13 deletions
+26 -3
View File
@@ -13,7 +13,7 @@ class Home extends BaseController
{
$public_path = FCPATH;
$ansible_folder = str_replace("public/", "ANSIBLE", $public_path);
$mysql = "SELECT id, internal_url,product_id,status FROM members_products";
$mysql = "SELECT id, uid, internal_url,product_id,status FROM members_products";
$query = $this->db->query($mysql);
// $num = $query->num_rows();
$provision_list= $query->getResult();
@@ -21,14 +21,37 @@ class Home extends BaseController
foreach ($provision_list as $pr){
$productId = $pr->product_id;
$provisionUID = $pr->uid;
$ContainerName= $productId.str_pad( $pr->id, 10, "0", STR_PAD_LEFT);
$partFolder = $ansible_folder."/parts/".$provisionUID;
if (!dir($partFolder) ){
mkdir($partFolder, 0700);
}
// THIS PROVISONING COMPOSERS
$composer_template_path = $ansible_folder."/templates/composers/".$productId."/docker-compose.yml";
$prov_name = str_replace(".", "_", $pr->internal_url).".yml";
$template_file = $ansible_folder ."/templates/".$pr->product_id.".yml";
//Get the domposer template file
$composer_template_contents = file_get_contents($composer_template_path);
// Do the processing
$composer_template_contents = str_replace("WHAT_CONTAINER_NAME", $ContainerName, $composer_template_contents);
$destinationHomeFolder = "/home/chiefsoft/".$ContainerName;
$composer_template_contents = str_replace("DESTINATION_FOLDER", $destinationHomeFolder, $composer_template_contents);
//Save to the specific path
$destination_composer_path = $ansible_folder."/parts/".$provisionUID."/docker-compose.yml";
$composerFile = fopen( $destination_composer_path, "w") or die("Unable to open file!");
fwrite($composerFile, $composer_template_contents);
fclose($composerFile);
// GET THE TEMPLATE FOR THIS PROVISIONING
$template_content = file_get_contents($template_file);
$template_content_processed = str_replace("WHAT_HOST_IN_USE", $productId."_SERVER", $template_content);;
$template_content_processed = str_replace("WHAT_HOST_IN_USE", $productId."_SERVER", $template_content);
$template_content_processed = str_replace("WHAT_PART_FOLDER", $partFolder, $template_content_processed);
$template_content_processed = str_replace("DESTINATION_FOLDER", $destinationHomeFolder, $template_content_processed);
// CREATE PROVISOINING FILE
$myfile = fopen( $ansible_folder ."/".$prov_name, "w") or die("Unable to open file!");
fwrite($myfile, $template_content_processed);