Skip to content

Commit 5a07f15

Browse files
feat: make Mittwald database host IP resolution configurable
1 parent 27c1942 commit 5a07f15

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

deployer/feature/config/set.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@
6969
* Database Manager
7070
*/
7171
set('database_manager_type', 'default');
72+
73+
// Resolve the Mittwald database hostname to its IP and pin it in .env (workaround for DNS
74+
// flapping of freshly created databases). Disabled by default, since pinning the IP breaks
75+
// when Mittwald rotates IPs or enforces TLS against the hostname. Enable only if affected by
76+
// DNS flapping.
77+
set('mittwald_resolve_host_to_ip', false);

deployer/feature/task/feature_sync.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ function waitForDatabaseHost(): void
7575
*/
7676
function resolveDatabaseHostToIp(string $hostname): void
7777
{
78+
if (!get('mittwald_resolve_host_to_ip', false)) {
79+
debug("Hostname-to-IP resolution disabled, keeping host {$hostname} in .env.");
80+
return;
81+
}
82+
7883
$resolveCmd = sprintf('echo gethostbyname("%s");', $hostname);
7984
$ip = trim(run("php -r " . escapeshellarg($resolveCmd)));
8085

docs/DATABASE.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ set('mittwald_project_id', 'your-project-id');
8686
| `mittwald_database_collation` | `utf8mb4_unicode_ci` | Collation |
8787
| `mittwald_database_wait` | `30` | Polling interval in seconds |
8888
| `mittwald_database_retries` | `20` | Max retry attempts |
89+
| `mittwald_resolve_host_to_ip` | `false` | Pin the resolved IP in `.env` instead of the hostname (see DNS flapping) |
8990

9091
### DNS flapping
9192

92-
After database creation the DNS entry for the database host (e.g. `mysql-xyz.pg-s-xxx.db.project.host`) may not be resolvable immediately and can flap intermittently. The feature sync task resolves the database hostname to an IP address in the `.env` file to bypass this issue.
93+
After database creation the DNS entry for the database host (e.g. `mysql-xyz.pg-s-xxx.db.project.host`) may not be resolvable immediately and can flap intermittently.
94+
95+
As a workaround, the database hostname can be resolved to its IP address once (while DNS is known to work) and pinned in the `.env` file, bypassing DNS for all subsequent commands. This is **disabled by default** (`mittwald_resolve_host_to_ip` = `false`), because pinning the IP breaks when Mittwald rotates database IPs or enforces TLS against the hostname. Enable it only for projects actually affected by DNS flapping:
96+
97+
```php
98+
set('mittwald_resolve_host_to_ip', true);
99+
```

src/Database/Manager/MittwaldApi.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ private function initDatabaseConfiguration(MySqlDatabase $database, MySqlUser $u
300300
*/
301301
private function resolveHostnameToIp(string $hostname): string
302302
{
303+
if (!get('mittwald_resolve_host_to_ip', false)) {
304+
debug("Hostname-to-IP resolution disabled, using hostname {$hostname}.");
305+
return $hostname;
306+
}
307+
303308
try {
304309
$resolveCmd = sprintf('echo gethostbyname("%s");', addslashes($hostname));
305310
$ip = trim(run("php -r " . escapeshellarg($resolveCmd)));

0 commit comments

Comments
 (0)