provision fix
This commit is contained in:
@@ -173,6 +173,69 @@ class Provision extends BaseController
|
||||
return view('welcome_message');
|
||||
}
|
||||
|
||||
private function prepareDockerComposer(
|
||||
$members_product_id,
|
||||
$members_product_port,
|
||||
$product_id,
|
||||
$member_product_uid,
|
||||
$member_id,
|
||||
$internal_url
|
||||
){
|
||||
|
||||
$public_path = FCPATH;
|
||||
$ansible_folder = str_replace("public/", "ANSIBLE", $public_path);
|
||||
$partMachineLocal = $_ENV['PATH_MACHINE_LOCAL'];
|
||||
|
||||
$subscriptionId = $members_product_id;
|
||||
$provisionPort = $members_product_port;
|
||||
$productId = $product_id;
|
||||
$provisionUID = $member_product_uid;
|
||||
$memberID = $member_id;
|
||||
$ContainerName = $this->generatedContainerName($productId, $members_product_id ); // $productId . str_pad($pr->id, 10, "0", STR_PAD_LEFT);
|
||||
$partFolder = $ansible_folder . "/parts/" . $member_product_uid;
|
||||
|
||||
$allocatedPort = $provisionPort;
|
||||
$this->updateToNow($provisionUID);
|
||||
|
||||
if (!is_dir($partFolder)) {
|
||||
mkdir($partFolder, 0700);
|
||||
}
|
||||
|
||||
// THIS PROVISONING COMPOSERS
|
||||
$composer_template_path = $ansible_folder . "/templates/composers/" . $productId . "/docker-compose.yml";
|
||||
$composer_template_path_local = $partMachineLocal . $provisionUID;
|
||||
|
||||
$prov_name = str_replace(".", "_", $internal_url) . ".yml";
|
||||
$template_file = $ansible_folder . "/templates/" . $productId . ".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/SITES/" . $ContainerName;
|
||||
$destinationHomeFolder =$_ENV['DESTINATION_HOME_FOLDER'] . $ContainerName;
|
||||
$composer_template_contents = str_replace("DESTINATION_FOLDER", $destinationHomeFolder, $composer_template_contents);
|
||||
$composer_template_contents = str_replace("ALLOCATED_PORT", $allocatedPort, $composer_template_contents);
|
||||
$composer_template_contents = str_replace("CNT_DB_NAME", $ContainerName, $composer_template_contents);
|
||||
$composer_template_contents = str_replace("CNT_DB_PASS", $provisionUID, $composer_template_contents);
|
||||
$composer_template_contents = str_replace("CNT_DB_DATA", '172.16.4.96:3307', $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_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 PROVISOINING FILE
|
||||
$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){
|
||||
|
||||
/*
|
||||
@@ -332,7 +395,10 @@ class Provision extends BaseController
|
||||
$mysql ="SELECT pp.uid AS prov_uid, p.id AS mpid,
|
||||
p.product_id, pp.id AS plan_id, pp.uid ,
|
||||
pp.provision_id, pp.play_file,
|
||||
p.uid AS member_product_uid
|
||||
p.uid AS member_product_uid ,
|
||||
p.member_id AS member_id ,
|
||||
p.internal_url ,
|
||||
p.provision_port
|
||||
FROM provision_plans pp
|
||||
LEFT JOIN members_products p ON p.id =pp.provision_id
|
||||
ORDER BY pp.updated ASC LIMIT ".$PROCESS_LIMIT;
|
||||
@@ -346,6 +412,12 @@ class Provision extends BaseController
|
||||
$productUid = $pr->member_product_uid;
|
||||
$playbook = $pr->product_id.".yml";
|
||||
$provisionUID = $pr->prov_uid;
|
||||
$member_id = $pr->member_id;
|
||||
$internal_url = $pr->internal_url;
|
||||
$provision_port = $pr->provision_port;
|
||||
$members_product_id = $pr->mpid;
|
||||
|
||||
|
||||
|
||||
log_message('critical', "Members Product ID ***** ".$pr->mpid);
|
||||
|
||||
@@ -371,6 +443,16 @@ class Provision extends BaseController
|
||||
mkdir($this_composer_part_location , 0700);
|
||||
}
|
||||
|
||||
$this->prepareDockerComposer(
|
||||
$members_product_id,
|
||||
$provision_port,
|
||||
$productId,
|
||||
$productUid,
|
||||
$member_id,
|
||||
$internal_url
|
||||
);
|
||||
|
||||
|
||||
|
||||
$this->db->query("UPDATE provision_plans SET updated = now() WHERE id = $planId");
|
||||
$this->db->query("UPDATE members_products SET p_file = p_file + 1 WHERE id = $provisionId");
|
||||
|
||||
Reference in New Issue
Block a user