Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deployer/feature/config/set.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 5 additions & 0 deletions deployer/feature/task/feature_sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

Expand Down
9 changes: 8 additions & 1 deletion docs/DATABASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```
5 changes: 5 additions & 0 deletions src/Database/Manager/MittwaldApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down