fix: add subpath for services

This commit is contained in:
Andras Bacsai 2024-05-22 15:45:30 +02:00
parent 6c3b4070ba
commit 80ada9c90a
2 changed files with 25 additions and 11 deletions

View File

@ -110,16 +110,18 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
$fqdn = Url::fromString($resourceFqdns); $fqdn = Url::fromString($resourceFqdns);
$port = $fqdn->getPort(); $port = $fqdn->getPort();
$path = $fqdn->getPath();
$fqdn = $fqdn->getScheme() . '://' . $fqdn->getHost(); $fqdn = $fqdn->getScheme() . '://' . $fqdn->getHost();
if ($generatedEnv) { if ($generatedEnv) {
$generatedEnv->value = $fqdn; $generatedEnv->value = $fqdn . $path;
$generatedEnv->save(); $generatedEnv->save();
} }
if ($port) { if ($port) {
$variableName = $variableName . "_$port"; $variableName = $variableName . "_$port";
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
// ray($generatedEnv);
if ($generatedEnv) { if ($generatedEnv) {
$generatedEnv->value = $fqdn . ':' . $port; $generatedEnv->value = $fqdn . ':' . $port . $path;
$generatedEnv->save(); $generatedEnv->save();
} }
} }
@ -127,17 +129,18 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
$url = Url::fromString($fqdn); $url = Url::fromString($fqdn);
$port = $url->getPort(); $port = $url->getPort();
$path = $url->getPath();
$url = $url->getHost(); $url = $url->getHost();
if ($generatedEnv) { if ($generatedEnv) {
$url = Str::of($fqdn)->after('://'); $url = Str::of($fqdn)->after('://');
$generatedEnv->value = $url; $generatedEnv->value = $url . $path;
$generatedEnv->save(); $generatedEnv->save();
} }
if ($port) { if ($port) {
$variableName = $variableName . "_$port"; $variableName = $variableName . "_$port";
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
if ($generatedEnv) { if ($generatedEnv) {
$generatedEnv->value = $url . ':' . $port; $generatedEnv->value = $url . ':' . $port . $path;
$generatedEnv->save(); $generatedEnv->save();
} }
} }
@ -146,6 +149,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$host = Url::fromString($fqdn); $host = Url::fromString($fqdn);
$port = $host->getPort(); $port = $host->getPort();
$url = $host->getHost(); $url = $host->getHost();
$path = $host->getPath();
$host = $host->getScheme() . '://' . $host->getHost(); $host = $host->getScheme() . '://' . $host->getHost();
if ($port) { if ($port) {
$port_envs = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'like', "SERVICE_FQDN_%_$port")->get(); $port_envs = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'like', "SERVICE_FQDN_%_$port")->get();
@ -153,10 +157,10 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$service_fqdn = str($port_env->key)->beforeLast('_')->after('SERVICE_FQDN_'); $service_fqdn = str($port_env->key)->beforeLast('_')->after('SERVICE_FQDN_');
$env = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'SERVICE_FQDN_' . $service_fqdn)->first(); $env = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'SERVICE_FQDN_' . $service_fqdn)->first();
if ($env) { if ($env) {
$env->value = $host; $env->value = $host . $path;
$env->save(); $env->save();
} }
$port_env->value = $host . ':' . $port; $port_env->value = $host . ':' . $port . $path;
$port_env->save(); $port_env->save();
} }
$port_envs_url = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'like', "SERVICE_URL_%_$port")->get(); $port_envs_url = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'like', "SERVICE_URL_%_$port")->get();
@ -164,17 +168,17 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$service_url = str($port_env_url->key)->beforeLast('_')->after('SERVICE_URL_'); $service_url = str($port_env_url->key)->beforeLast('_')->after('SERVICE_URL_');
$env = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'SERVICE_URL_' . $service_url)->first(); $env = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'SERVICE_URL_' . $service_url)->first();
if ($env) { if ($env) {
$env->value = $url; $env->value = $url . $path;
$env->save(); $env->save();
} }
$port_env_url->value = $url . ':' . $port; $port_env_url->value = $url . ':' . $port . $path;
$port_env_url->save(); $port_env_url->save();
} }
} else { } else {
$variableName = "SERVICE_FQDN_" . Str::of($resource->name)->upper()->replace('-', ''); $variableName = "SERVICE_FQDN_" . Str::of($resource->name)->upper()->replace('-', '');
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
$fqdn = Url::fromString($fqdn); $fqdn = Url::fromString($fqdn);
$fqdn = $fqdn->getScheme() . '://' . $fqdn->getHost(); $fqdn = $fqdn->getScheme() . '://' . $fqdn->getHost() . $fqdn->getPath();
if ($generatedEnv) { if ($generatedEnv) {
$generatedEnv->value = $fqdn; $generatedEnv->value = $fqdn;
$generatedEnv->save(); $generatedEnv->save();
@ -182,7 +186,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
$variableName = "SERVICE_URL_" . Str::of($resource->name)->upper()->replace('-', ''); $variableName = "SERVICE_URL_" . Str::of($resource->name)->upper()->replace('-', '');
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first(); $generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
$url = Url::fromString($fqdn); $url = Url::fromString($fqdn);
$url = $url->getHost(); $url = $url->getHost() . $url->getPath();
if ($generatedEnv) { if ($generatedEnv) {
$url = Str::of($fqdn)->after('://'); $url = Str::of($fqdn)->after('://');
$generatedEnv->value = $url; $generatedEnv->value = $url;

View File

@ -1011,7 +1011,6 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
'service_id' => $resource->id, 'service_id' => $resource->id,
])->first(); ])->first();
if ($env) { if ($env) {
$env_url = Url::fromString($savedService->fqdn); $env_url = Url::fromString($savedService->fqdn);
$env_port = $env_url->getPort(); $env_port = $env_url->getPort();
if ($env_port !== $predefinedPort) { if ($env_port !== $predefinedPort) {
@ -1053,6 +1052,17 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
} }
if ($foundEnv) { if ($foundEnv) {
$fqdn = data_get($foundEnv, 'value'); $fqdn = data_get($foundEnv, 'value');
// if ($savedService->fqdn) {
// $savedServiceFqdn = Url::fromString($savedService->fqdn);
// $parsedFqdn = Url::fromString($fqdn);
// $savedServicePath = $savedServiceFqdn->getPath();
// $parsedFqdnPath = $parsedFqdn->getPath();
// if ($savedServicePath != $parsedFqdnPath) {
// $fqdn = $parsedFqdn->withPath($savedServicePath)->__toString();
// $foundEnv->value = $fqdn;
// $foundEnv->save();
// }
// }
} else { } else {
if ($command->value() === 'URL') { if ($command->value() === 'URL') {
$fqdn = Str::of($fqdn)->after('://')->value(); $fqdn = Str::of($fqdn)->after('://')->value();