WIP: got the env variables to set in the php pod, need to make them dynamically be added rather than coded directly into lamp.rs
This commit is contained in:
		
							parent
							
								
									6653cebb87
								
							
						
					
					
						commit
						ac24eb6206
					
				| @ -1,16 +1,16 @@ | ||||
| <?php | ||||
| 
 | ||||
| ini_set('display_errors', 1); | ||||
| ini_set('display_startup_errors', 1); | ||||
| error_reporting(E_ALL); | ||||
| 
 | ||||
| $host = getenv('MYSQL_HOST') ?: 'localhost'; | ||||
| $db   = 'testfill'; | ||||
| // Load dynamic secrets from environment
 | ||||
| $host = getenv('MYSQL_HOST') ?: ''; | ||||
| $user = getenv('MYSQL_USER') ?: 'root'; | ||||
| $pass = getenv('MYSQL_PASSWORD') ?: ''; | ||||
| $db   = 'testfill'; | ||||
| $charset = 'utf8mb4'; | ||||
| 
 | ||||
| // Setup PDO
 | ||||
| // Connect to MariaDB
 | ||||
| $dsn = "mysql:host=$host;charset=$charset"; | ||||
| $options = [ | ||||
|     PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, | ||||
| @ -28,57 +28,55 @@ try { | ||||
|         ) | ||||
|     ");
 | ||||
| } catch (\PDOException $e) { | ||||
|     die("Database setup failed: " . $e->getMessage()); | ||||
|     die("❌ DB connection failed: " . $e->getMessage()); | ||||
| } | ||||
| 
 | ||||
| // Disk usage (PVC mount path)
 | ||||
| $mountPath = '/var/lib/mysql'; // Change this if PVC is mounted elsewhere
 | ||||
| $freeBytes = disk_free_space($mountPath); | ||||
| $totalBytes = disk_total_space($mountPath); | ||||
| $freeGB = round($freeBytes / (1024 ** 3), 2); | ||||
| $totalGB = round($totalBytes / (1024 ** 3), 2); | ||||
| $usedGB = round(($totalBytes - $freeBytes) / (1024 ** 3), 2); | ||||
| // Get database size from information_schema
 | ||||
| try { | ||||
|     $stmt = $pdo->query(" | ||||
|         SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS total_size_gb | ||||
|         FROM information_schema.tables | ||||
|         WHERE table_schema = 'testfill' | ||||
|     ");
 | ||||
|     $dbSize = $stmt->fetch()['total_size_gb'] ?? '0'; | ||||
| } catch (Exception $e) { | ||||
|     $dbSize = 'N/A'; | ||||
| } | ||||
| 
 | ||||
| $message = ''; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fill'])) { | ||||
|      | ||||
| 
 | ||||
| 
 | ||||
|     $chunkSize = 1024 * 1024; // 1MB
 | ||||
|     $iterations = 1024;       // 1GB total
 | ||||
|     $data = str_repeat(random_bytes(1024), 1024); // ~1MB binary blob
 | ||||
| 
 | ||||
|     // Insert ~1GB of binary data
 | ||||
|     $iterations = 1024; | ||||
|     $data = str_repeat(random_bytes(1024), 1024); // 1MB
 | ||||
|     $stmt = $pdo->prepare("INSERT INTO filler (data) VALUES (:data)"); | ||||
| 
 | ||||
|     for ($i = 0; $i < $iterations; $i++) { | ||||
|         $stmt->execute([':data' => $data]); | ||||
|     } | ||||
| 
 | ||||
|     // Recalculate DB size
 | ||||
|     $stmt = $pdo->query(" | ||||
|         SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS total_size_gb | ||||
|         FROM information_schema.tables | ||||
|         WHERE table_schema = 'testfill' | ||||
|     ");
 | ||||
|     $dbSize = $stmt->fetch()['total_size_gb'] ?? '0'; | ||||
| 
 | ||||
|     clearstatcache(); | ||||
|     $freeBytes = disk_free_space($mountPath); | ||||
|     $freeGB = round($freeBytes / (1024 ** 3), 2); | ||||
|     $usedGB = round(($totalBytes - $freeBytes) / (1024 ** 3), 2); | ||||
| 
 | ||||
|     $message = "<p style='color: green;'>✅ 1GB inserted. Disk usage updated.</p>"; | ||||
|     $message = "<p style='color: green;'>✅ 1GB inserted into MariaDB successfully.</p>"; | ||||
| } | ||||
| ?>
 | ||||
| 
 | ||||
| <!DOCTYPE html> | ||||
| <html> | ||||
| <head> | ||||
|     <title>Volume Filler</title> | ||||
|     <title>MariaDB Filler</title> | ||||
| </head> | ||||
| <body> | ||||
|     <h1>Kubernetes PVC Filler</h1> | ||||
|     <h1>MariaDB Storage Filler</h1> | ||||
|     <?= $message ?>
 | ||||
|     <ul> | ||||
|         <li>Total PVC Space: <?= $totalGB ?> GB</li>
 | ||||
|         <li>Used PVC Space: <?= $usedGB ?> GB</li>
 | ||||
|         <li>Free PVC Space: <?= $freeGB ?> GB</li>
 | ||||
|         <li><strong>MariaDB Used Size:</strong> <?= $dbSize ?> GB</li>
 | ||||
|     </ul> | ||||
| 
 | ||||
|     <form method="post"> | ||||
| @ -87,4 +85,3 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST'&& isset($_POST['fill'])) { | ||||
| </body> | ||||
| </html> | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -113,7 +113,18 @@ impl<T: Topology + K8sclient + HelmCommand> Interpret<T> for LAMPInterpret { | ||||
|                     } | ||||
|                 } | ||||
|             }, | ||||
|             ]), | ||||
|             { | ||||
|                 "name": "MYSQL_HOST", | ||||
|                 "value": "harmony-lamp-demo-database-mariadb" | ||||
|             }, | ||||
|             { | ||||
|                 "name": "MYSQL_DATABASE", | ||||
|                 "value": "testfill" | ||||
|             }, | ||||
|             { | ||||
|                 "name": "MYSQL_USER", | ||||
|                 "value": "root" 
 | ||||
|             }]), | ||||
|         }; | ||||
| 
 | ||||
|         info!("Deploying score {deployment_score:#?}"); | ||||
| @ -257,6 +268,13 @@ opcache.fast_shutdown=1 | ||||
|              sed -i 's/ServerSignature On/ServerSignature Off/' /etc/apache2/conf-enabled/security.conf" | ||||
|         )); | ||||
| 
 | ||||
|         // Set env vars
 | ||||
|         dockerfile.push(RUN::from( | ||||
|             "echo 'PassEnv MYSQL_PASSWORD' >> /etc/apache2/sites-available/000-default.conf \ | ||||
|              && echo 'PassEnv MYSQL_USER' >> /etc/apache2/sites-available/000-default.conf \ | ||||
|              && echo 'PassEnv MYSQL_HOST' >> /etc/apache2/sites-available/000-default.conf" | ||||
|         )); | ||||
| 
 | ||||
|         // Create a dedicated user for running Apache
 | ||||
|         dockerfile.push(RUN::from( | ||||
|             "groupadd -g 1000 appuser && \ | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user