fix(services): update environment variable naming convention to use underscores instead of dashes for SERVICE_FQDN and SERVICE_URL

This commit is contained in:
Andras Bacsai
2025-07-18 20:18:12 +02:00
parent 4df349f74d
commit 9ed77e5eef
2 changed files with 16 additions and 11 deletions

View File

@@ -119,7 +119,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$resourceFqdns = str($resource->fqdn)->explode(','); $resourceFqdns = str($resource->fqdn)->explode(',');
if ($resourceFqdns->count() === 1) { if ($resourceFqdns->count() === 1) {
$resourceFqdns = $resourceFqdns->first(); $resourceFqdns = $resourceFqdns->first();
$variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', ''); $variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', '_');
$generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class) $generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class)
->where('resourceable_id', $resource->service_id) ->where('resourceable_id', $resource->service_id)
->where('key', $variableName) ->where('key', $variableName)
@@ -151,7 +151,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$generatedEnv->save(); $generatedEnv->save();
} }
} }
$variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', ''); $variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '_');
$generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class) $generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class)
->where('resourceable_id', $resource->service_id) ->where('resourceable_id', $resource->service_id)
->where('key', $variableName) ->where('key', $variableName)
@@ -243,7 +243,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$port_env_url->save(); $port_env_url->save();
} }
} else { } else {
$variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', ''); $variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', '_');
$generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class) $generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class)
->where('resourceable_id', $resource->service_id) ->where('resourceable_id', $resource->service_id)
->where('key', $variableName) ->where('key', $variableName)
@@ -254,7 +254,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$generatedEnv->value = $fqdn; $generatedEnv->value = $fqdn;
$generatedEnv->save(); $generatedEnv->save();
} }
$variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', ''); $variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '_');
$generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class) $generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class)
->where('resourceable_id', $resource->service_id) ->where('resourceable_id', $resource->service_id)
->where('key', $variableName) ->where('key', $variableName)

View File

@@ -3080,11 +3080,8 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
} }
} elseif ($isService) { } elseif ($isService) {
if (blank($savedService->fqdn)) { if (blank($savedService->fqdn)) {
if ($fqdnFor) { // For services, if no explicit FQDN is set, leave SERVICE_FQDN_ variables empty
$fqdn = generateFqdn($server, "$fqdnFor-$uuid"); $fqdn = '';
} else {
$fqdn = generateFqdn($server, "{$savedService->name}-$uuid");
}
} else { } else {
$fqdn = str($savedService->fqdn)->after('://')->before(':')->prepend(str($savedService->fqdn)->before('://')->append('://'))->value(); $fqdn = str($savedService->fqdn)->after('://')->before(':')->prepend(str($savedService->fqdn)->before('://')->append('://'))->value();
} }
@@ -3150,6 +3147,10 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
if ($isApplication && $resource->build_pack === 'dockercompose') { if ($isApplication && $resource->build_pack === 'dockercompose') {
continue; continue;
} }
// For services, only generate FQDN if explicit FQDN is set
if ($isService && blank($savedService->fqdn)) {
continue;
}
$fqdnFor = $key->after('SERVICE_FQDN_')->lower()->value(); $fqdnFor = $key->after('SERVICE_FQDN_')->lower()->value();
if (str($fqdnFor)->contains('_')) { if (str($fqdnFor)->contains('_')) {
$fqdnFor = str($fqdnFor)->before('_'); $fqdnFor = str($fqdnFor)->before('_');
@@ -3168,6 +3169,10 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
if ($isApplication && $resource->build_pack === 'dockercompose') { if ($isApplication && $resource->build_pack === 'dockercompose') {
continue; continue;
} }
// For services, only generate URL if explicit FQDN is set
if ($isService && blank($savedService->fqdn)) {
continue;
}
$fqdnFor = $key->after('SERVICE_URL_')->lower()->value(); $fqdnFor = $key->after('SERVICE_URL_')->lower()->value();
if (str($fqdnFor)->contains('_')) { if (str($fqdnFor)->contains('_')) {
$fqdnFor = str($fqdnFor)->before('_'); $fqdnFor = str($fqdnFor)->before('_');
@@ -3674,8 +3679,8 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
$coolifyScheme = $coolifyUrl->getScheme(); $coolifyScheme = $coolifyUrl->getScheme();
$coolifyFqdn = $coolifyUrl->getHost(); $coolifyFqdn = $coolifyUrl->getHost();
$coolifyUrl = $coolifyUrl->withScheme($coolifyScheme)->withHost($coolifyFqdn)->withPort(null); $coolifyUrl = $coolifyUrl->withScheme($coolifyScheme)->withHost($coolifyFqdn)->withPort(null);
$coolifyEnvironments->put('SERVICE_URL_'.str($forServiceName)->upper(), $coolifyUrl->__toString()); $coolifyEnvironments->put('SERVICE_URL_'.str($forServiceName)->upper()->replace('-', '_'), $coolifyUrl->__toString());
$coolifyEnvironments->put('SERVICE_FQDN_'.str($forServiceName)->upper(), $coolifyFqdn); $coolifyEnvironments->put('SERVICE_FQDN_'.str($forServiceName)->upper()->replace('-', '_'), $coolifyFqdn);
} }
} }
} }