clean up provison

This commit is contained in:
CHIEFSOFT\ameye
2025-09-15 18:02:35 -04:00
parent 296d157924
commit 6ced10281f
+39 -7
View File
@@ -192,7 +192,7 @@ class Provision extends BaseController
// $templateRandom = 'P' . rand(1, 6);
// $composer_template_contents = str_replace("TEMPLATE_NAME_REPLACE", $templateRandom, $composer_template_contents);
$composer_template_contents = $this->prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID, $ansible_folder, $productId);
$composer_template_contents = $this->prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID, $ansible_folder, $productId, $pr->internal_url);
//Save to the specific path
// $destination_composer_path = $ansible_folder . "/parts/" . $provisionUID . "/docker-compose.yml";
@@ -210,20 +210,22 @@ class Provision extends BaseController
$myfile = fopen($ansible_folder . "/" . $prov_name, "w") or die("Unable to open file!");
fwrite($myfile, $template_content_processed);
fclose($myfile);
$this->registerProvision($subscriptionId, $prov_name);
$this->provisionActions($memberID, $provisionUID, "Auto Configuration Started");
}
return 0;
}
private function prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID, $ansible_folder, $productId): string
private function prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID, $ansible_folder, $productId, $internalUrl): string
{
$PROVISION_IMAGE_NAME = match ($productId) {
"A000001" => "registry.chiefsoft.com/pweb/pweb-01-merms-pweb0006c:latest",
"A000002" => "registry.chiefsoft.com/bweb/bweb-01-merms-pweb0006c:latest",
default => '',
};
$partMachineLocal = $_ENV['PATH_MACHINE_LOCAL'];
$SITE_CONTENTS_GATEWAY = $_ENV['SITE_CONTENTS_GATEWAY'];
$SITE_CONTACT_GATEWAY = $_ENV['SITE_CONTACT_GATEWAY'];
$MYSQL_PROVISION_DATABASE_PORT = $_ENV['PROVISION_MSQL_DATABASE_IP'] . ":" . $_ENV['PROVISION_MSQL_DATABASE_PORT']; // "172.16.4.96:3307";
@@ -250,6 +252,33 @@ class Provision extends BaseController
} catch (\Exception $e) {
log_message('critical', "***** ***** prepareTemplateFile Error:: () " . $e->getMessage());
}
$composer_template_path = $ansible_folder . "/templates/composers/" . $productId . "/docker-compose.yml";
$composer_template_path_local = $partMachineLocal . $provisionUID;
$prov_name = str_replace(".", "_", $pr->internal_url) . ".yml";
$template_file = $ansible_folder . "/templates/" . $productId . ".yml";
$partFolder = $ansible_folder . "/parts/" . $provisionUID;
if (!is_dir($partFolder)) {
mkdir($partFolder, 0700);
}
try {
$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_PART_FOLDER", $partFolder, $template_content_processed);
$template_content_processed = str_replace("DESTINATION_FOLDER", $destinationHomeFolder, $template_content_processed);
$template_content_processed = str_replace("WHAT_PART_LOCAL", $composer_template_path_local, $template_content_processed); // depends on the local machine
// CREATE PROVISIONING FILE
$myfile = fopen($ansible_folder . "/" . $prov_name, "w") or die("Unable to open file!");
fwrite($myfile, $template_content_processed);
fclose($myfile);
} catch (\Exception $e) {
log_message('critical', "***** ***** prepareTemplateFile Error:: () " . $e->getMessage());
}
// GET THE TEMPLATE FOR THIS PROVISIONING
return $composer_template_contents;
}
@@ -379,7 +408,7 @@ class Provision extends BaseController
$member_product_uid,
$member_id,
$internal_url
)
): void
{
@@ -439,7 +468,7 @@ class Provision extends BaseController
// $templateRandom = 'P' . rand(1, 6);
// $composer_template_contents = str_replace("TEMPLATE_NAME_REPLACE", $templateRandom, $composer_template_contents);
//
$composer_template_contents = $this->prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID, $ansible_folder, $productId);
$composer_template_contents = $this->prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID, $ansible_folder, $productId, $internal_url);
//Save to the specific path
// $composerFile = fopen($destination_composer_path, "w") or die("Unable to open file!");
@@ -447,6 +476,7 @@ class Provision extends BaseController
// 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_PART_FOLDER", $partFolder, $template_content_processed);
@@ -456,6 +486,7 @@ class Provision extends BaseController
$myfile = fopen($ansible_folder . "/" . $prov_name, "w") or die("Unable to open file!");
fwrite($myfile, $template_content_processed);
fclose($myfile);
*/
}
private function registerProvision($subscriptionId, $prov_name)
@@ -538,7 +569,7 @@ class Provision extends BaseController
$maxItem = $maxItem + 1;
}
$portF = $maxItem;
} catch (Exception $e) {
} catch (\Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
return $portF;
@@ -546,6 +577,7 @@ class Provision extends BaseController
private function provisionServer($productId)
{
$primaryServer ="";
switch ($productId) {
case "A000001":
case "A000002":
@@ -579,7 +611,7 @@ class Provision extends BaseController
[A000005_SERVER]
172.16.4.95
*/
private function updateToNow($provisionUID)
private function updateToNow($provisionUID):void
{
try {
$mysql = "UPDATE members_products SET updated=now(),