fix(deployment): refactor domain parsing and environment variable generation using Spatie URL library

This commit is contained in:
Andras Bacsai
2025-07-08 10:42:34 +02:00
parent 95da765a9e
commit 94f9c54256
2 changed files with 19 additions and 12 deletions

View File

@@ -30,6 +30,7 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Sleep; use Illuminate\Support\Sleep;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use RuntimeException; use RuntimeException;
use Spatie\Url\Url;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Throwable; use Throwable;
use Visus\Cuid2\Cuid2; use Visus\Cuid2\Cuid2;
@@ -933,10 +934,12 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$parsedDomain = data_get($domain, 'domain'); $parsedDomain = data_get($domain, 'domain');
if (filled($parsedDomain)) { if (filled($parsedDomain)) {
$parsedDomain = str($parsedDomain)->explode(',')->first(); $parsedDomain = str($parsedDomain)->explode(',')->first();
$coolifyUrl = str($parsedDomain)->after('://')->before(':')->prepend(str($parsedDomain)->before('://')->append('://')); $coolifyUrl = Url::fromString($parsedDomain);
$coolifyFqdn = str($parsedDomain)->replace('http://', '')->replace('https://', '')->before(':'); $coolifyScheme = $coolifyUrl->getScheme();
$envs->push('SERVICE_URL_'.str($forServiceName)->upper().'='.$coolifyUrl->value()); $coolifyFqdn = $coolifyUrl->getHost();
$envs->push('SERVICE_FQDN_'.str($forServiceName)->upper().'='.$coolifyFqdn->value()); $coolifyUrl = $coolifyUrl->withScheme($coolifyScheme)->withHost($coolifyFqdn)->withPort(null);
$envs->push('SERVICE_URL_'.str($forServiceName)->upper().'='.$coolifyUrl->__toString());
$envs->push('SERVICE_FQDN_'.str($forServiceName)->upper().'='.$coolifyFqdn);
} }
} }
} }
@@ -964,10 +967,12 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$parsedDomain = data_get($domain, 'domain'); $parsedDomain = data_get($domain, 'domain');
if (filled($parsedDomain)) { if (filled($parsedDomain)) {
$parsedDomain = str($parsedDomain)->explode(',')->first(); $parsedDomain = str($parsedDomain)->explode(',')->first();
$coolifyUrl = str($parsedDomain)->after('://')->before(':')->prepend(str($parsedDomain)->before('://')->append('://')); $coolifyUrl = Url::fromString($parsedDomain);
$coolifyFqdn = str($parsedDomain)->replace('http://', '')->replace('https://', '')->before(':'); $coolifyScheme = $coolifyUrl->getScheme();
$envs->push('SERVICE_URL_'.str($forServiceName)->upper().'='.$coolifyUrl->value()); $coolifyFqdn = $coolifyUrl->getHost();
$envs->push('SERVICE_FQDN_'.str($forServiceName)->upper().'='.$coolifyFqdn->value()); $coolifyUrl = $coolifyUrl->withScheme($coolifyScheme)->withHost($coolifyFqdn)->withPort(null);
$envs->push('SERVICE_URL_'.str($forServiceName)->upper().'='.$coolifyUrl->__toString());
$envs->push('SERVICE_FQDN_'.str($forServiceName)->upper().'='.$coolifyFqdn);
} }
} }
} }

View File

@@ -3670,10 +3670,12 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$parsedDomain = data_get($domain, 'domain'); $parsedDomain = data_get($domain, 'domain');
if (filled($parsedDomain)) { if (filled($parsedDomain)) {
$parsedDomain = str($parsedDomain)->explode(',')->first(); $parsedDomain = str($parsedDomain)->explode(',')->first();
$coolifyUrl = str($parsedDomain)->after('://')->before(':')->prepend(str($parsedDomain)->before('://')->append('://')); $coolifyUrl = Url::fromString($parsedDomain);
$coolifyFqdn = str($parsedDomain)->replace('http://', '')->replace('https://', '')->before(':'); $coolifyScheme = $coolifyUrl->getScheme();
$coolifyEnvironments->put('SERVICE_URL_'.str($forServiceName)->upper(), $coolifyUrl->value()); $coolifyFqdn = $coolifyUrl->getHost();
$coolifyEnvironments->put('SERVICE_FQDN_'.str($forServiceName)->upper(), $coolifyFqdn->value()); $coolifyUrl = $coolifyUrl->withScheme($coolifyScheme)->withHost($coolifyFqdn)->withPort(null);
$coolifyEnvironments->put('SERVICE_URL_'.str($forServiceName)->upper(), $coolifyUrl->__toString());
$coolifyEnvironments->put('SERVICE_FQDN_'.str($forServiceName)->upper(), $coolifyFqdn);
} }
} }
} }