teemplate cleanup

This commit is contained in:
CHIEFSOFT\ameye
2025-09-15 15:24:28 -04:00
parent da81fafa2d
commit 296d157924
+32 -15
View File
@@ -192,13 +192,13 @@ class Provision extends BaseController
// $templateRandom = 'P' . rand(1, 6); // $templateRandom = 'P' . rand(1, 6);
// $composer_template_contents = str_replace("TEMPLATE_NAME_REPLACE", $templateRandom, $composer_template_contents); // $composer_template_contents = str_replace("TEMPLATE_NAME_REPLACE", $templateRandom, $composer_template_contents);
$composer_template_contents = $this->prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID); $composer_template_contents = $this->prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID, $ansible_folder, $productId);
//Save to the specific path //Save to the specific path
$destination_composer_path = $ansible_folder . "/parts/" . $provisionUID . "/docker-compose.yml"; // $destination_composer_path = $ansible_folder . "/parts/" . $provisionUID . "/docker-compose.yml";
$composerFile = fopen($destination_composer_path, "w") or die("Unable to open file!"); // $composerFile = fopen($destination_composer_path, "w") or die("Unable to open file!");
fwrite($composerFile, $composer_template_contents); // fwrite($composerFile, $composer_template_contents);
fclose($composerFile); // fclose($composerFile);
// GET THE TEMPLATE FOR THIS PROVISIONING // GET THE TEMPLATE FOR THIS PROVISIONING
$template_content = file_get_contents($template_file); $template_content = file_get_contents($template_file);
@@ -216,8 +216,13 @@ class Provision extends BaseController
return 0; return 0;
} }
private function prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID): string private function prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID, $ansible_folder, $productId): 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 => '',
};
$SITE_CONTENTS_GATEWAY = $_ENV['SITE_CONTENTS_GATEWAY']; $SITE_CONTENTS_GATEWAY = $_ENV['SITE_CONTENTS_GATEWAY'];
$SITE_CONTACT_GATEWAY = $_ENV['SITE_CONTACT_GATEWAY']; $SITE_CONTACT_GATEWAY = $_ENV['SITE_CONTACT_GATEWAY'];
@@ -231,14 +236,24 @@ class Provision extends BaseController
$composer_template_contents = str_replace("CNT_DB_PASS", $provisionUID, $composer_template_contents); $composer_template_contents = str_replace("CNT_DB_PASS", $provisionUID, $composer_template_contents);
$composer_template_contents = str_replace("CNT_DB_DATA", $MYSQL_PROVISION_DATABASE_PORT, $composer_template_contents); $composer_template_contents = str_replace("CNT_DB_DATA", $MYSQL_PROVISION_DATABASE_PORT, $composer_template_contents);
$composer_template_contents = str_replace("PROVISION_UID_REPLACE", $provisionUID, $composer_template_contents); $composer_template_contents = str_replace("PROVISION_UID_REPLACE", $provisionUID, $composer_template_contents);
$composer_template_contents = str_replace("PROVISION_IMAGE_NAME_REPLACE", "registry.chiefsoft.com/pweb/pweb-01-merms-pweb0006c:latest", $composer_template_contents); $composer_template_contents = str_replace("PROVISION_IMAGE_NAME_REPLACE", $PROVISION_IMAGE_NAME, $composer_template_contents);
$composer_template_contents = str_replace("SITE_CONTENTS_URL_REPLACE", $SITE_CONTENTS_GATEWAY, $composer_template_contents); $composer_template_contents = str_replace("SITE_CONTENTS_URL_REPLACE", $SITE_CONTENTS_GATEWAY, $composer_template_contents);
$composer_template_contents = str_replace("SITE_CONTACT_URL_REPLACE", $SITE_CONTACT_GATEWAY, $composer_template_contents); $composer_template_contents = str_replace("SITE_CONTACT_URL_REPLACE", $SITE_CONTACT_GATEWAY, $composer_template_contents);
$composer_template_contents = str_replace("TEMPLATE_NAME_REPLACE", $templateRandom, $composer_template_contents); $composer_template_contents = str_replace("TEMPLATE_NAME_REPLACE", $templateRandom, $composer_template_contents);
try {
//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);
} catch (\Exception $e) {
log_message('critical', "***** ***** prepareTemplateFile Error:: () " . $e->getMessage());
}
return $composer_template_contents; return $composer_template_contents;
} }
private function scheduleRefreshAction() private function scheduleRefreshAction(): void
{ {
$mysql = "SELECT * FROM member_product_refresh WHERE product_id IN ('A000001','A000002') AND status =0 LIMIT 1"; $mysql = "SELECT * FROM member_product_refresh WHERE product_id IN ('A000001','A000002') AND status =0 LIMIT 1";
$query = $this->db->query($mysql); $query = $this->db->query($mysql);
@@ -248,11 +263,13 @@ class Provision extends BaseController
foreach ($provision_list as $pr) { foreach ($provision_list as $pr) {
$this->db->query("UPDATE member_product_refresh SET status = status + 1 WHERE id = " . $pr->id); $this->db->query("UPDATE member_product_refresh SET status = status + 1 WHERE id = " . $pr->id);
$subscriptionUId = $pr->subscription_uid; $subscriptionUId = $pr->subscription_uid;
$this->refreshProvision($subscriptionUId); if ($this->refreshProvision($subscriptionUId) == 100) {
log_message('critical', "***** ***** scheduleRefreshAction Started:: () ");
}
} }
} }
private function refreshProvision($subscriptionUId) private function refreshProvision($subscriptionUId): int
{ {
log_message('critical', "***** ***** refreshProvision :: Execute Refresh Provisioning() "); log_message('critical', "***** ***** refreshProvision :: Execute Refresh Provisioning() ");
$rsyncPass = "******noNEDD****"; $rsyncPass = "******noNEDD****";
@@ -352,7 +369,7 @@ class Provision extends BaseController
$this->update_To_Completed($productUid); $this->update_To_Completed($productUid);
} }
} }
return 0; return 100;
} }
private function prepareDockerComposer( private function prepareDockerComposer(
@@ -422,12 +439,12 @@ class Provision extends BaseController
// $templateRandom = 'P' . rand(1, 6); // $templateRandom = 'P' . rand(1, 6);
// $composer_template_contents = str_replace("TEMPLATE_NAME_REPLACE", $templateRandom, $composer_template_contents); // $composer_template_contents = str_replace("TEMPLATE_NAME_REPLACE", $templateRandom, $composer_template_contents);
// //
$composer_template_contents = $this->prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID); $composer_template_contents = $this->prepareTemplateFile($composer_template_contents, $ContainerName, $allocatedPort, $provisionUID, $ansible_folder, $productId);
//Save to the specific path //Save to the specific path
$composerFile = fopen($destination_composer_path, "w") or die("Unable to open file!"); // $composerFile = fopen($destination_composer_path, "w") or die("Unable to open file!");
fwrite($composerFile, $composer_template_contents); // fwrite($composerFile, $composer_template_contents);
fclose($composerFile); // fclose($composerFile);
// GET THE TEMPLATE FOR THIS PROVISIONING // GET THE TEMPLATE FOR THIS PROVISIONING
$template_content = file_get_contents($template_file); $template_content = file_get_contents($template_file);