diff --git a/deployer/feature/config/set.php b/deployer/feature/config/set.php index 413b254..0f6d238 100644 --- a/deployer/feature/config/set.php +++ b/deployer/feature/config/set.php @@ -69,3 +69,9 @@ * Database Manager */ set('database_manager_type', 'default'); + +// Resolve the Mittwald database hostname to its IP and pin it in .env (workaround for DNS +// flapping of freshly created databases). Disabled by default, since pinning the IP breaks +// when Mittwald rotates IPs or enforces TLS against the hostname. Enable only if affected by +// DNS flapping. +set('mittwald_resolve_host_to_ip', false); diff --git a/deployer/feature/task/feature_sync.php b/deployer/feature/task/feature_sync.php index da54ef2..5865194 100644 --- a/deployer/feature/task/feature_sync.php +++ b/deployer/feature/task/feature_sync.php @@ -75,6 +75,11 @@ function waitForDatabaseHost(): void */ function resolveDatabaseHostToIp(string $hostname): void { + if (!get('mittwald_resolve_host_to_ip', false)) { + debug("Hostname-to-IP resolution disabled, keeping host {$hostname} in .env."); + return; + } + $resolveCmd = sprintf('echo gethostbyname("%s");', $hostname); $ip = trim(run("php -r " . escapeshellarg($resolveCmd))); diff --git a/docs/DATABASE.md b/docs/DATABASE.md index bdd408a..e408095 100644 --- a/docs/DATABASE.md +++ b/docs/DATABASE.md @@ -86,7 +86,14 @@ set('mittwald_project_id', 'your-project-id'); | `mittwald_database_collation` | `utf8mb4_unicode_ci` | Collation | | `mittwald_database_wait` | `30` | Polling interval in seconds | | `mittwald_database_retries` | `20` | Max retry attempts | +| `mittwald_resolve_host_to_ip` | `false` | Pin the resolved IP in `.env` instead of the hostname (see DNS flapping) | ### DNS flapping -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. +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. + +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: + +```php +set('mittwald_resolve_host_to_ip', true); +``` diff --git a/src/Database/Manager/MittwaldApi.php b/src/Database/Manager/MittwaldApi.php index 9cda528..283f5f7 100644 --- a/src/Database/Manager/MittwaldApi.php +++ b/src/Database/Manager/MittwaldApi.php @@ -300,6 +300,11 @@ private function initDatabaseConfiguration(MySqlDatabase $database, MySqlUser $u */ private function resolveHostnameToIp(string $hostname): string { + if (!get('mittwald_resolve_host_to_ip', false)) { + debug("Hostname-to-IP resolution disabled, using hostname {$hostname}."); + return $hostname; + } + try { $resolveCmd = sprintf('echo gethostbyname("%s");', addslashes($hostname)); $ip = trim(run("php -r " . escapeshellarg($resolveCmd)));