fix: modified env vars to use values from helm deployment
This commit is contained in:
parent
ac24eb6206
commit
df3c8ee2a6
@ -3,14 +3,12 @@
|
|||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
// Load dynamic secrets from environment
|
|
||||||
$host = getenv('MYSQL_HOST') ?: '';
|
$host = getenv('MYSQL_HOST') ?: '';
|
||||||
$user = getenv('MYSQL_USER') ?: 'root';
|
$user = getenv('MYSQL_USER') ?: 'root';
|
||||||
$pass = getenv('MYSQL_PASSWORD') ?: '';
|
$pass = getenv('MYSQL_PASSWORD') ?: '';
|
||||||
$db = 'testfill';
|
$db = 'testfill';
|
||||||
$charset = 'utf8mb4';
|
$charset = 'utf8mb4';
|
||||||
|
|
||||||
// Connect to MariaDB
|
|
||||||
$dsn = "mysql:host=$host;charset=$charset";
|
$dsn = "mysql:host=$host;charset=$charset";
|
||||||
$options = [
|
$options = [
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
@ -18,10 +16,10 @@ $options = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$pdo = new PDO($dsn, $user, $pass, $options);
|
$pdo = new PDO($dsn, $user, $pass, $options);
|
||||||
$pdo->exec("CREATE DATABASE IF NOT EXISTS `$db`");
|
$pdo->exec("CREATE DATABASE IF NOT EXISTS `$db`");
|
||||||
$pdo->exec("USE `$db`");
|
$pdo->exec("USE `$db`");
|
||||||
$pdo->exec("
|
$pdo->exec("
|
||||||
CREATE TABLE IF NOT EXISTS filler (
|
CREATE TABLE IF NOT EXISTS filler (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
data LONGBLOB
|
data LONGBLOB
|
||||||
@ -31,22 +29,26 @@ try {
|
|||||||
die("❌ DB connection failed: " . $e->getMessage());
|
die("❌ DB connection failed: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get database size from information_schema
|
function getDbStats($pdo, $db) {
|
||||||
try {
|
|
||||||
$stmt = $pdo->query("
|
$stmt = $pdo->query("
|
||||||
SELECT ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS total_size_gb
|
SELECT
|
||||||
|
ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 2) AS total_size_gb,
|
||||||
|
SUM(table_rows) AS total_rows
|
||||||
FROM information_schema.tables
|
FROM information_schema.tables
|
||||||
WHERE table_schema = 'testfill'
|
WHERE table_schema = '$db'
|
||||||
");
|
");
|
||||||
$dbSize = $stmt->fetch()['total_size_gb'] ?? '0';
|
$result = $stmt->fetch();
|
||||||
} catch (Exception $e) {
|
$sizeGb = $result['total_size_gb'] ?? '0';
|
||||||
$dbSize = 'N/A';
|
$rows = $result['total_rows'] ?? '0';
|
||||||
|
$avgMb = ($rows > 0) ? round(($sizeGb * 1024) / $rows, 2) : 0;
|
||||||
|
return [$sizeGb, $rows, $avgMb];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list($dbSize, $rowCount, $avgRowMb) = getDbStats($pdo, $db);
|
||||||
|
|
||||||
$message = '';
|
$message = '';
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fill'])) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fill'])) {
|
||||||
// Insert ~1GB of binary data
|
|
||||||
$iterations = 1024;
|
$iterations = 1024;
|
||||||
$data = str_repeat(random_bytes(1024), 1024); // 1MB
|
$data = str_repeat(random_bytes(1024), 1024); // 1MB
|
||||||
$stmt = $pdo->prepare("INSERT INTO filler (data) VALUES (:data)");
|
$stmt = $pdo->prepare("INSERT INTO filler (data) VALUES (:data)");
|
||||||
@ -55,13 +57,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fill'])) {
|
|||||||
$stmt->execute([':data' => $data]);
|
$stmt->execute([':data' => $data]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recalculate DB size
|
list($dbSize, $rowCount, $avgRowMb) = getDbStats($pdo, $db);
|
||||||
$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';
|
|
||||||
|
|
||||||
$message = "<p style='color: green;'>✅ 1GB inserted into MariaDB successfully.</p>";
|
$message = "<p style='color: green;'>✅ 1GB inserted into MariaDB successfully.</p>";
|
||||||
}
|
}
|
||||||
@ -76,7 +72,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['fill'])) {
|
|||||||
<h1>MariaDB Storage Filler</h1>
|
<h1>MariaDB Storage Filler</h1>
|
||||||
<?= $message ?>
|
<?= $message ?>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>MariaDB Used Size:</strong> <?= $dbSize ?> GB</li>
|
<li><strong>📦 MariaDB Used Size:</strong> <?= $dbSize ?> GB</li>
|
||||||
|
<li><strong>📊 Total Rows:</strong> <?= $rowCount ?></li>
|
||||||
|
<li><strong>📐 Average Row Size:</strong> <?= $avgRowMb ?> MB</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
|
|||||||
@ -115,16 +115,9 @@ impl<T: Topology + K8sclient + HelmCommand> Interpret<T> for LAMPInterpret {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "MYSQL_HOST",
|
"name": "MYSQL_HOST",
|
||||||
"value": "harmony-lamp-demo-database-mariadb"
|
"value": secret_name
|
||||||
},
|
},
|
||||||
{
|
]),
|
||||||
"name": "MYSQL_DATABASE",
|
|
||||||
"value": "testfill"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "MYSQL_USER",
|
|
||||||
"value": "root"
|
|
||||||
}]),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("Deploying score {deployment_score:#?}");
|
info!("Deploying score {deployment_score:#?}");
|
||||||
@ -272,7 +265,7 @@ opcache.fast_shutdown=1
|
|||||||
dockerfile.push(RUN::from(
|
dockerfile.push(RUN::from(
|
||||||
"echo 'PassEnv MYSQL_PASSWORD' >> /etc/apache2/sites-available/000-default.conf \
|
"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_USER' >> /etc/apache2/sites-available/000-default.conf \
|
||||||
&& echo 'PassEnv MYSQL_HOST' >> /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
|
// Create a dedicated user for running Apache
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user