refactor: Update shared.php to include predefined ports for services
This commit is contained in:
@@ -2928,6 +2928,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
|
|
||||||
$allMagicEnvironments = collect([]);
|
$allMagicEnvironments = collect([]);
|
||||||
foreach ($services as $serviceName => $service) {
|
foreach ($services as $serviceName => $service) {
|
||||||
|
$predefinedPort = null;
|
||||||
$magicEnvironments = collect([]);
|
$magicEnvironments = collect([]);
|
||||||
$image = data_get_str($service, 'image');
|
$image = data_get_str($service, 'image');
|
||||||
$environment = collect(data_get($service, 'environment', []));
|
$environment = collect(data_get($service, 'environment', []));
|
||||||
@@ -2936,6 +2937,24 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
$isDatabase = isDatabaseImage(data_get_str($service, 'image'));
|
$isDatabase = isDatabaseImage(data_get_str($service, 'image'));
|
||||||
|
|
||||||
if ($isService) {
|
if ($isService) {
|
||||||
|
$containerName = "$serviceName-{$resource->uuid}";
|
||||||
|
|
||||||
|
if ($serviceName === 'registry') {
|
||||||
|
$tempServiceName = 'docker-registry';
|
||||||
|
} else {
|
||||||
|
$tempServiceName = $serviceName;
|
||||||
|
}
|
||||||
|
if (str(data_get($service, 'image'))->contains('glitchtip')) {
|
||||||
|
$tempServiceName = 'glitchtip';
|
||||||
|
}
|
||||||
|
if ($serviceName === 'supabase-kong') {
|
||||||
|
$tempServiceName = 'supabase';
|
||||||
|
}
|
||||||
|
$serviceDefinition = data_get($allServices, $tempServiceName);
|
||||||
|
$predefinedPort = data_get($serviceDefinition, 'port');
|
||||||
|
if ($serviceName === 'plausible') {
|
||||||
|
$predefinedPort = '8000';
|
||||||
|
}
|
||||||
if ($isDatabase) {
|
if ($isDatabase) {
|
||||||
$savedService = ServiceDatabase::firstOrCreate([
|
$savedService = ServiceDatabase::firstOrCreate([
|
||||||
'name' => $serviceName,
|
'name' => $serviceName,
|
||||||
@@ -2987,8 +3006,10 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
// SERVICE_FQDN_APP or SERVICE_FQDN_APP_3000
|
// SERVICE_FQDN_APP or SERVICE_FQDN_APP_3000
|
||||||
if (substr_count(str($key)->value(), '_') === 3) {
|
if (substr_count(str($key)->value(), '_') === 3) {
|
||||||
$fqdnFor = $key->after('SERVICE_FQDN_')->beforeLast('_')->lower()->value();
|
$fqdnFor = $key->after('SERVICE_FQDN_')->beforeLast('_')->lower()->value();
|
||||||
|
$port = $key->afterLast('_')->value();
|
||||||
} else {
|
} else {
|
||||||
$fqdnFor = $key->after('SERVICE_FQDN_')->lower()->value();
|
$fqdnFor = $key->after('SERVICE_FQDN_')->lower()->value();
|
||||||
|
$port = null;
|
||||||
}
|
}
|
||||||
if ($isApplication) {
|
if ($isApplication) {
|
||||||
$fqdn = generateFqdn($server, "{$resource->name}-$uuid");
|
$fqdn = generateFqdn($server, "{$resource->name}-$uuid");
|
||||||
@@ -2999,19 +3020,24 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
$fqdn = generateFqdn($server, "{$savedService->name}-$uuid");
|
$fqdn = generateFqdn($server, "{$savedService->name}-$uuid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value && get_class($value) === 'Illuminate\Support\Stringable' && $value->startsWith('/')) {
|
if ($value && get_class($value) === 'Illuminate\Support\Stringable' && $value->startsWith('/')) {
|
||||||
$path = $value->value();
|
$path = $value->value();
|
||||||
if ($path !== '/') {
|
if ($path !== '/') {
|
||||||
$fqdn = "$fqdn$path";
|
$fqdn = "$fqdn$path";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$fqdnWithPort = $fqdn;
|
||||||
|
if ($port) {
|
||||||
|
$fqdnWithPort = "$fqdn:$port";
|
||||||
|
}
|
||||||
if ($isApplication && is_null($resource->fqdn)) {
|
if ($isApplication && is_null($resource->fqdn)) {
|
||||||
data_forget($resource, 'environment_variables');
|
data_forget($resource, 'environment_variables');
|
||||||
data_forget($resource, 'environment_variables_preview');
|
data_forget($resource, 'environment_variables_preview');
|
||||||
$resource->fqdn = $fqdn;
|
$resource->fqdn = $fqdnWithPort;
|
||||||
$resource->save();
|
$resource->save();
|
||||||
} elseif ($isService && is_null($savedService->fqdn)) {
|
} elseif ($isService && is_null($savedService->fqdn)) {
|
||||||
$savedService->fqdn = $fqdn;
|
$savedService->fqdn = $fqdnWithPort;
|
||||||
$savedService->save();
|
$savedService->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3040,7 +3066,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
}
|
}
|
||||||
|
|
||||||
$allMagicEnvironments = $allMagicEnvironments->merge($magicEnvironments);
|
$allMagicEnvironments = $allMagicEnvironments->merge($magicEnvironments);
|
||||||
|
|
||||||
if ($magicEnvironments->count() > 0) {
|
if ($magicEnvironments->count() > 0) {
|
||||||
foreach ($magicEnvironments as $key => $value) {
|
foreach ($magicEnvironments as $key => $value) {
|
||||||
$key = str($key);
|
$key = str($key);
|
||||||
|
Reference in New Issue
Block a user