From 657b26c548ee1b545f54e3ec324e7e7dfc028f80 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Sun, 19 Jan 2025 20:16:22 -0500 Subject: [PATCH] Provisoning upgades --- .gitignore | 3 +++ ANSIBLE/inventory | 10 ++++++++++ ANSIBLE/templates/A000003.yml | 13 +++---------- app/Controllers/Home.php | 29 ++++++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 ANSIBLE/inventory diff --git a/.gitignore b/.gitignore index 0ee30ca..dc7d607 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ apache_log/error.log writable writable* .idea +ANSIBLE/parts +ANSIBLE/parts/* + diff --git a/ANSIBLE/inventory b/ANSIBLE/inventory new file mode 100644 index 0000000..d0e18da --- /dev/null +++ b/ANSIBLE/inventory @@ -0,0 +1,10 @@ +[A000001_SERVER] +172.16.4.92 +[A000002_SERVER] +172.16.4.92 +[A000003_SERVER] +172.16.4.91 +[A000004_SERVER] +172.16.4.91 +[A000005_SERVER] +172.16.4.95 \ No newline at end of file diff --git a/ANSIBLE/templates/A000003.yml b/ANSIBLE/templates/A000003.yml index 84b3c4a..d0a2d66 100644 --- a/ANSIBLE/templates/A000003.yml +++ b/ANSIBLE/templates/A000003.yml @@ -1,20 +1,13 @@ --- - hosts: WHAT_HOST_IN_USE - vars_files: - - vars/main.yml tasks: - name: Set up docker-compose file template: - src: "files/docker-compose.yml" - dest: "/home/{{ admin_user }}/wordpress/" - - - name: Set permission for docker daemon - file: - path: /var/run/docker.sock - mode: '0770' + src: "WHAT_PART_FOLDER/docker-compose.yml" + dest: "DESTINATION_FOLDER" - name: docker compose up shell: - chdir: "/home/{{ admin_user }}/wordpress/" + chdir: "DESTINATION_FOLDER/" cmd: docker-compose up -d \ No newline at end of file diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 36a0d25..3365d12 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -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);