mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-26 01:10:30 -04:00
fix(domains): ignore hostless URLs in deployment and port overrides
This commit is contained in:
@@ -9,3 +9,6 @@
|
||||
## Displayed defaults must not become stored overrides
|
||||
- When an edit form shows an inherited or computed default, trace an unchanged save and a related-field edit through persistence.
|
||||
- Preserve the inherited state when the displayed value still equals the computed default; store an override only when the user selects a different value.
|
||||
|
||||
## Prove regressions against the unchanged baseline
|
||||
- For a bug fix, run the same regression test before and after the production change. Use a stash when requested so the failure and success come from the exact same test.
|
||||
|
||||
@@ -2403,15 +2403,20 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
|
||||
$fqdn = $this->preview->fqdn;
|
||||
}
|
||||
if (isset($fqdn)) {
|
||||
$domains = str($fqdn)->explode(',')->map(fn (string $domain) => trim($domain))->filter();
|
||||
$url = $domains->map(fn (string $domain) => Url::fromString($domain)->withPort(null)->__toString())->implode(',');
|
||||
$fqdn = $domains->map(fn (string $domain) => Url::fromString($domain)->getHost())->implode(',');
|
||||
if ((int) $this->application->compose_parsing_version >= 3) {
|
||||
$this->coolify_variables .= 'COOLIFY_URL='.escapeShellValue($url).' ';
|
||||
$this->coolify_variables .= 'COOLIFY_FQDN='.escapeShellValue($fqdn).' ';
|
||||
} else {
|
||||
$this->coolify_variables .= 'COOLIFY_URL='.escapeShellValue($fqdn).' ';
|
||||
$this->coolify_variables .= 'COOLIFY_FQDN='.escapeShellValue($url).' ';
|
||||
$domains = str($fqdn)->explode(',')
|
||||
->map(fn (string $domain) => trim($domain))
|
||||
->filter()
|
||||
->filter(fn (string $domain) => isValidDomainUrl($domain));
|
||||
if ($domains->isNotEmpty()) {
|
||||
$url = $domains->map(fn (string $domain) => Url::fromString($domain)->withPort(null)->__toString())->implode(',');
|
||||
$fqdn = $domains->map(fn (string $domain) => Url::fromString($domain)->getHost())->implode(',');
|
||||
if ((int) $this->application->compose_parsing_version >= 3) {
|
||||
$this->coolify_variables .= 'COOLIFY_URL='.escapeShellValue($url).' ';
|
||||
$this->coolify_variables .= 'COOLIFY_FQDN='.escapeShellValue($fqdn).' ';
|
||||
} else {
|
||||
$this->coolify_variables .= 'COOLIFY_URL='.escapeShellValue($fqdn).' ';
|
||||
$this->coolify_variables .= 'COOLIFY_FQDN='.escapeShellValue($url).' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($this->application->git_branch)) {
|
||||
|
||||
@@ -34,6 +34,7 @@ class DomainPortOverrides
|
||||
$normalizedDomains = collect(explode(',', $fqdn))
|
||||
->map(fn (string $domain): string => trim($domain))
|
||||
->filter()
|
||||
->filter(fn (string $domain): bool => isValidDomainUrl($domain))
|
||||
->map(function (string $domain) use ($existingOverrides): array {
|
||||
$portlessDomain = self::withoutPort($domain);
|
||||
$parts = DomainUrlParts::split($domain);
|
||||
|
||||
@@ -44,6 +44,7 @@ function coolifyVariablesForFqdn(string $fqdn, string $composeParsingVersion = '
|
||||
// The created hook resets this, so it has to be set afterwards.
|
||||
$application->compose_parsing_version = $composeParsingVersion;
|
||||
$application->save();
|
||||
Application::withoutGlobalScopes()->whereKey($application->id)->update(['fqdn' => $fqdn]);
|
||||
|
||||
$job = new TestableCoolifyUrlDeploymentJob;
|
||||
$reflection = new ReflectionClass(ApplicationDeploymentJob::class);
|
||||
@@ -92,3 +93,19 @@ it('still resolves a single domain', function () {
|
||||
->toContain("COOLIFY_URL='https://a.example.com'")
|
||||
->toContain("COOLIFY_FQDN='a.example.com'");
|
||||
});
|
||||
|
||||
it('ignores a hostless stored domain while setting deployment variables', function () {
|
||||
$variables = coolifyVariablesForFqdn('https://,https://a.example.com');
|
||||
|
||||
expect($variables)
|
||||
->toContain("COOLIFY_URL='https://a.example.com'")
|
||||
->toContain("COOLIFY_FQDN='a.example.com'");
|
||||
});
|
||||
|
||||
it('does not set domain variables for a hostless stored fqdn', function () {
|
||||
$variables = coolifyVariablesForFqdn('https://');
|
||||
|
||||
expect($variables)
|
||||
->not->toContain('COOLIFY_URL=')
|
||||
->not->toContain('COOLIFY_FQDN=');
|
||||
});
|
||||
|
||||
@@ -34,3 +34,25 @@ it('keeps an explicit override on the paired domain', function (string $source,
|
||||
'www redirect' => ['https://example.com', 'https://www.example.com'],
|
||||
'non-www redirect' => ['https://www.example.com', 'https://example.com'],
|
||||
]);
|
||||
|
||||
it('drops hostless domains and their port overrides', function () {
|
||||
$result = DomainPortOverrides::normalize(
|
||||
'https://,https://example.com',
|
||||
[
|
||||
'https://' => 3000,
|
||||
'https://example.com' => 8080,
|
||||
],
|
||||
);
|
||||
|
||||
expect($result)->toBe([
|
||||
'fqdn' => 'https://example.com',
|
||||
'overrides' => ['https://example.com' => 8080],
|
||||
]);
|
||||
});
|
||||
|
||||
it('clears an fqdn that contains only a hostless domain', function () {
|
||||
expect(DomainPortOverrides::normalize('https://', ['https://' => 3000]))->toBe([
|
||||
'fqdn' => null,
|
||||
'overrides' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user