fix(application): streamline environment variable updates for Docker Compose services and enhance FQDN generation logic
This commit is contained in:
@@ -4,7 +4,6 @@ namespace App\Livewire\Project\Application;
|
|||||||
|
|
||||||
use App\Actions\Application\GenerateConfig;
|
use App\Actions\Application\GenerateConfig;
|
||||||
use App\Models\Application;
|
use App\Models\Application;
|
||||||
use App\Models\EnvironmentVariable;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Spatie\Url\Url;
|
use Spatie\Url\Url;
|
||||||
@@ -270,7 +269,6 @@ class General extends Component
|
|||||||
$this->application->save();
|
$this->application->save();
|
||||||
$this->dispatch('success', 'Domain generated.');
|
$this->dispatch('success', 'Domain generated.');
|
||||||
if ($this->application->build_pack === 'dockercompose') {
|
if ($this->application->build_pack === 'dockercompose') {
|
||||||
$this->updateServiceEnvironmentVariables();
|
|
||||||
$this->loadComposeFile(showToast: false);
|
$this->loadComposeFile(showToast: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,7 +342,7 @@ class General extends Component
|
|||||||
$this->application->custom_labels = base64_encode($this->customLabels);
|
$this->application->custom_labels = base64_encode($this->customLabels);
|
||||||
$this->application->save();
|
$this->application->save();
|
||||||
if ($this->application->build_pack === 'dockercompose') {
|
if ($this->application->build_pack === 'dockercompose') {
|
||||||
$this->loadComposeFile();
|
$this->loadComposeFile(showToast: false);
|
||||||
}
|
}
|
||||||
$this->dispatch('configurationChanged');
|
$this->dispatch('configurationChanged');
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
@@ -421,7 +419,7 @@ class General extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->application->build_pack === 'dockercompose' && $this->initialDockerComposeLocation !== $this->application->docker_compose_location) {
|
if ($this->application->build_pack === 'dockercompose' && $this->initialDockerComposeLocation !== $this->application->docker_compose_location) {
|
||||||
$compose_return = $this->loadComposeFile();
|
$compose_return = $this->loadComposeFile(showToast: false);
|
||||||
if ($compose_return instanceof \Livewire\Features\SupportEvents\Event) {
|
if ($compose_return instanceof \Livewire\Features\SupportEvents\Event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -470,7 +468,6 @@ class General extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->application->docker_compose_domains = json_encode($originalDomains);
|
$this->application->docker_compose_domains = json_encode($originalDomains);
|
||||||
|
|
||||||
foreach ($originalDomains as $serviceName => $service) {
|
foreach ($originalDomains as $serviceName => $service) {
|
||||||
$domain = data_get($service, 'domain');
|
$domain = data_get($service, 'domain');
|
||||||
if ($domain) {
|
if ($domain) {
|
||||||
@@ -486,12 +483,6 @@ class General extends Component
|
|||||||
}
|
}
|
||||||
$this->application->custom_labels = base64_encode($this->customLabels);
|
$this->application->custom_labels = base64_encode($this->customLabels);
|
||||||
$this->application->save();
|
$this->application->save();
|
||||||
|
|
||||||
// Update SERVICE_FQDN_ and SERVICE_URL_ environment variables for Docker Compose applications
|
|
||||||
if ($this->application->build_pack === 'dockercompose') {
|
|
||||||
$this->updateServiceEnvironmentVariables();
|
|
||||||
}
|
|
||||||
|
|
||||||
$showToaster && ! $warning && $this->dispatch('success', 'Application settings updated!');
|
$showToaster && ! $warning && $this->dispatch('success', 'Application settings updated!');
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$originalFqdn = $this->application->getOriginal('fqdn');
|
$originalFqdn = $this->application->getOriginal('fqdn');
|
||||||
@@ -525,25 +516,33 @@ class General extends Component
|
|||||||
foreach ($domains as $serviceName => $service) {
|
foreach ($domains as $serviceName => $service) {
|
||||||
$serviceNameFormatted = str($serviceName)->upper()->replace('-', '_');
|
$serviceNameFormatted = str($serviceName)->upper()->replace('-', '_');
|
||||||
$domain = data_get($service, 'domain');
|
$domain = data_get($service, 'domain');
|
||||||
|
// Delete SERVICE_FQDN_ and SERVICE_URL_ variables if domain is removed
|
||||||
|
$this->application->environment_variables()->where('resourceable_type', Application::class)
|
||||||
|
->where('resourceable_id', $this->application->id)
|
||||||
|
->where('key', 'LIKE', "SERVICE_FQDN_{$serviceNameFormatted}%")
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
$this->application->environment_variables()->where('resourceable_type', Application::class)
|
||||||
|
->where('resourceable_id', $this->application->id)
|
||||||
|
->where('key', 'LIKE', "SERVICE_URL_{$serviceNameFormatted}%")
|
||||||
|
->delete();
|
||||||
|
|
||||||
if ($domain) {
|
if ($domain) {
|
||||||
// Create or update SERVICE_FQDN_ and SERVICE_URL_ variables
|
// Create or update SERVICE_FQDN_ and SERVICE_URL_ variables
|
||||||
$fqdn = Url::fromString($domain);
|
$fqdn = Url::fromString($domain);
|
||||||
$port = $fqdn->getPort();
|
$port = $fqdn->getPort();
|
||||||
$path = $fqdn->getPath();
|
$path = $fqdn->getPath();
|
||||||
$fqdnValue = $fqdn->getScheme().'://'.$fqdn->getHost();
|
$urlValue = $fqdn->getScheme().'://'.$fqdn->getHost();
|
||||||
if ($path !== '/') {
|
|
||||||
$fqdnValue = $fqdnValue.$path;
|
|
||||||
}
|
|
||||||
$urlValue = str($domain)->after('://');
|
|
||||||
if ($path !== '/') {
|
if ($path !== '/') {
|
||||||
$urlValue = $urlValue.$path;
|
$urlValue = $urlValue.$path;
|
||||||
}
|
}
|
||||||
|
$fqdnValue = str($domain)->after('://');
|
||||||
|
if ($path !== '/') {
|
||||||
|
$fqdnValue = $fqdnValue.$path;
|
||||||
|
}
|
||||||
|
|
||||||
// Create/update SERVICE_FQDN_
|
// Create/update SERVICE_FQDN_
|
||||||
EnvironmentVariable::updateOrCreate([
|
$this->application->environment_variables()->updateOrCreate([
|
||||||
'resourceable_type' => Application::class,
|
|
||||||
'resourceable_id' => $this->application->id,
|
|
||||||
'key' => "SERVICE_FQDN_{$serviceNameFormatted}",
|
'key' => "SERVICE_FQDN_{$serviceNameFormatted}",
|
||||||
], [
|
], [
|
||||||
'value' => $fqdnValue,
|
'value' => $fqdnValue,
|
||||||
@@ -552,21 +551,16 @@ class General extends Component
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Create/update SERVICE_URL_
|
// Create/update SERVICE_URL_
|
||||||
EnvironmentVariable::updateOrCreate([
|
$this->application->environment_variables()->updateOrCreate([
|
||||||
'resourceable_type' => Application::class,
|
|
||||||
'resourceable_id' => $this->application->id,
|
|
||||||
'key' => "SERVICE_URL_{$serviceNameFormatted}",
|
'key' => "SERVICE_URL_{$serviceNameFormatted}",
|
||||||
], [
|
], [
|
||||||
'value' => $urlValue,
|
'value' => $urlValue,
|
||||||
'is_build_time' => false,
|
'is_build_time' => false,
|
||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Create/update port-specific variables if port exists
|
// Create/update port-specific variables if port exists
|
||||||
if ($port) {
|
if (filled($port)) {
|
||||||
EnvironmentVariable::updateOrCreate([
|
$this->application->environment_variables()->updateOrCreate([
|
||||||
'resourceable_type' => Application::class,
|
|
||||||
'resourceable_id' => $this->application->id,
|
|
||||||
'key' => "SERVICE_FQDN_{$serviceNameFormatted}_{$port}",
|
'key' => "SERVICE_FQDN_{$serviceNameFormatted}_{$port}",
|
||||||
], [
|
], [
|
||||||
'value' => $fqdnValue,
|
'value' => $fqdnValue,
|
||||||
@@ -574,9 +568,7 @@ class General extends Component
|
|||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
EnvironmentVariable::updateOrCreate([
|
$this->application->environment_variables()->updateOrCreate([
|
||||||
'resourceable_type' => Application::class,
|
|
||||||
'resourceable_id' => $this->application->id,
|
|
||||||
'key' => "SERVICE_URL_{$serviceNameFormatted}_{$port}",
|
'key' => "SERVICE_URL_{$serviceNameFormatted}_{$port}",
|
||||||
], [
|
], [
|
||||||
'value' => $urlValue,
|
'value' => $urlValue,
|
||||||
@@ -584,17 +576,6 @@ class General extends Component
|
|||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Delete SERVICE_FQDN_ and SERVICE_URL_ variables if domain is removed
|
|
||||||
EnvironmentVariable::where('resourceable_type', Application::class)
|
|
||||||
->where('resourceable_id', $this->application->id)
|
|
||||||
->where('key', 'LIKE', "SERVICE_FQDN_{$serviceNameFormatted}%")
|
|
||||||
->delete();
|
|
||||||
|
|
||||||
EnvironmentVariable::where('resourceable_type', Application::class)
|
|
||||||
->where('resourceable_id', $this->application->id)
|
|
||||||
->where('key', 'LIKE', "SERVICE_URL_{$serviceNameFormatted}%")
|
|
||||||
->delete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -102,7 +102,7 @@ class Create extends Component
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$service->parse(isNew: true);
|
$service->parse(isNew: true, isOneClick: true);
|
||||||
|
|
||||||
return redirect()->route('project.service.configuration', [
|
return redirect()->route('project.service.configuration', [
|
||||||
'service_uuid' => $service->uuid,
|
'service_uuid' => $service->uuid,
|
||||||
|
@@ -1353,7 +1353,7 @@ class Application extends BaseModel
|
|||||||
public function parse(int $pull_request_id = 0, ?int $preview_id = null)
|
public function parse(int $pull_request_id = 0, ?int $preview_id = null)
|
||||||
{
|
{
|
||||||
if ((int) $this->compose_parsing_version >= 3) {
|
if ((int) $this->compose_parsing_version >= 3) {
|
||||||
return newParser($this, $pull_request_id, $preview_id);
|
return applicationParser($this, $pull_request_id, $preview_id);
|
||||||
} elseif ($this->docker_compose_raw) {
|
} elseif ($this->docker_compose_raw) {
|
||||||
return parseDockerComposeFile(resource: $this, isNew: false, pull_request_id: $pull_request_id, preview_id: $preview_id);
|
return parseDockerComposeFile(resource: $this, isNew: false, pull_request_id: $pull_request_id, preview_id: $preview_id);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1274,10 +1274,10 @@ class Service extends BaseModel
|
|||||||
instant_remote_process($commands, $this->server);
|
instant_remote_process($commands, $this->server);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parse(bool $isNew = false): Collection
|
public function parse(bool $isNew = false, bool $isOneClick = false): Collection
|
||||||
{
|
{
|
||||||
if ((int) $this->compose_parsing_version >= 3) {
|
if ((int) $this->compose_parsing_version >= 3) {
|
||||||
return newParser($this);
|
return serviceParser($this, isOneClick: $isOneClick);
|
||||||
} elseif ($this->docker_compose_raw) {
|
} elseif ($this->docker_compose_raw) {
|
||||||
return parseDockerComposeFile($this, $isNew);
|
return parseDockerComposeFile($this, $isNew);
|
||||||
} else {
|
} else {
|
||||||
|
1657
bootstrap/helpers/parsers.php
Normal file
1657
bootstrap/helpers/parsers.php
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Application;
|
use App\Models\Application;
|
||||||
use App\Models\EnvironmentVariable;
|
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
use App\Models\ServiceApplication;
|
use App\Models\ServiceApplication;
|
||||||
use App\Models\ServiceDatabase;
|
use App\Models\ServiceDatabase;
|
||||||
@@ -115,163 +114,71 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
|
|||||||
$resource->image = $updatedImage;
|
$resource->image = $updatedImage;
|
||||||
$resource->save();
|
$resource->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$serviceName = str($resource->name)->upper()->replace('-', '_');
|
||||||
|
$resource->service->environment_variables()->where('key', 'LIKE', "SERVICE_FQDN_{$serviceName}%")->delete();
|
||||||
|
$resource->service->environment_variables()->where('key', 'LIKE', "SERVICE_URL_{$serviceName}%")->delete();
|
||||||
|
|
||||||
if ($resource->fqdn) {
|
if ($resource->fqdn) {
|
||||||
$resourceFqdns = str($resource->fqdn)->explode(',');
|
$resourceFqdns = str($resource->fqdn)->explode(',');
|
||||||
if ($resourceFqdns->count() === 1) {
|
|
||||||
$resourceFqdns = $resourceFqdns->first();
|
$resourceFqdns = $resourceFqdns->first();
|
||||||
|
$variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '_');
|
||||||
|
$url = Url::fromString($resourceFqdns);
|
||||||
|
$port = $url->getPort();
|
||||||
|
$path = $url->getPath();
|
||||||
|
$urlValue = $url->getScheme().'://'.$url->getHost();
|
||||||
|
$urlValue = ($path === '/') ? $urlValue : $urlValue.$path;
|
||||||
|
$resource->service->environment_variables()->updateOrCreate([
|
||||||
|
'resourceable_type' => Service::class,
|
||||||
|
'resourceable_id' => $resource->service_id,
|
||||||
|
'key' => $variableName,
|
||||||
|
], [
|
||||||
|
'value' => $urlValue,
|
||||||
|
'is_build_time' => false,
|
||||||
|
'is_preview' => false,
|
||||||
|
]);
|
||||||
|
if ($port) {
|
||||||
|
$variableName = $variableName."_$port";
|
||||||
|
$resource->service->environment_variables()->updateOrCreate([
|
||||||
|
'resourceable_type' => Service::class,
|
||||||
|
'resourceable_id' => $resource->service_id,
|
||||||
|
'key' => $variableName,
|
||||||
|
], [
|
||||||
|
'value' => $urlValue,
|
||||||
|
'is_build_time' => false,
|
||||||
|
'is_preview' => false,
|
||||||
|
]);
|
||||||
|
}
|
||||||
$variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', '_');
|
$variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', '_');
|
||||||
$fqdn = Url::fromString($resourceFqdns);
|
$fqdn = Url::fromString($resourceFqdns);
|
||||||
$port = $fqdn->getPort();
|
$port = $fqdn->getPort();
|
||||||
$path = $fqdn->getPath();
|
$path = $fqdn->getPath();
|
||||||
$fqdn = $fqdn->getScheme().'://'.$fqdn->getHost();
|
$fqdn = $fqdn->getHost();
|
||||||
$fqdnValue = ($path === '/') ? $fqdn : $fqdn.$path;
|
$fqdnValue = str($fqdn)->after('://');
|
||||||
EnvironmentVariable::updateOrCreate([
|
|
||||||
'resourceable_type' => Service::class,
|
|
||||||
'resourceable_id' => $resource->service_id,
|
|
||||||
'key' => $variableName,
|
|
||||||
], [
|
|
||||||
'value' => $fqdnValue,
|
|
||||||
'is_build_time' => false,
|
|
||||||
'is_preview' => false,
|
|
||||||
]);
|
|
||||||
if ($port) {
|
|
||||||
$variableName = $variableName."_$port";
|
|
||||||
EnvironmentVariable::updateOrCreate([
|
|
||||||
'resourceable_type' => Service::class,
|
|
||||||
'resourceable_id' => $resource->service_id,
|
|
||||||
'key' => $variableName,
|
|
||||||
], [
|
|
||||||
'value' => $fqdnValue,
|
|
||||||
'is_build_time' => false,
|
|
||||||
'is_preview' => false,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
$variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '_');
|
|
||||||
$url = Url::fromString($fqdn);
|
|
||||||
$port = $url->getPort();
|
|
||||||
$path = $url->getPath();
|
|
||||||
$url = $url->getHost();
|
|
||||||
$urlValue = str($fqdn)->after('://');
|
|
||||||
if ($path !== '/') {
|
if ($path !== '/') {
|
||||||
$urlValue = $urlValue.$path;
|
$fqdnValue = $fqdnValue.$path;
|
||||||
}
|
}
|
||||||
EnvironmentVariable::updateOrCreate([
|
$resource->service->environment_variables()->updateOrCreate([
|
||||||
'resourceable_type' => Service::class,
|
'resourceable_type' => Service::class,
|
||||||
'resourceable_id' => $resource->service_id,
|
'resourceable_id' => $resource->service_id,
|
||||||
'key' => $variableName,
|
'key' => $variableName,
|
||||||
], [
|
], [
|
||||||
'value' => $urlValue,
|
'value' => $fqdnValue,
|
||||||
'is_build_time' => false,
|
'is_build_time' => false,
|
||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
]);
|
]);
|
||||||
if ($port) {
|
if ($port) {
|
||||||
$variableName = $variableName."_$port";
|
$variableName = $variableName."_$port";
|
||||||
EnvironmentVariable::updateOrCreate([
|
$resource->service->environment_variables()->updateOrCreate([
|
||||||
'resourceable_type' => Service::class,
|
'resourceable_type' => Service::class,
|
||||||
'resourceable_id' => $resource->service_id,
|
'resourceable_id' => $resource->service_id,
|
||||||
'key' => $variableName,
|
'key' => $variableName,
|
||||||
], [
|
], [
|
||||||
'value' => $urlValue,
|
'value' => $fqdnValue,
|
||||||
'is_build_time' => false,
|
'is_build_time' => false,
|
||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
} elseif ($resourceFqdns->count() > 1) {
|
|
||||||
foreach ($resourceFqdns as $fqdn) {
|
|
||||||
$host = Url::fromString($fqdn);
|
|
||||||
$port = $host->getPort();
|
|
||||||
$url = $host->getHost();
|
|
||||||
$path = $host->getPath();
|
|
||||||
$host = $host->getScheme().'://'.$host->getHost();
|
|
||||||
if ($port) {
|
|
||||||
$port_envs = EnvironmentVariable::where('resourceable_type', Service::class)
|
|
||||||
->where('resourceable_id', $resource->service_id)
|
|
||||||
->where('key', 'like', "SERVICE_FQDN_%_$port")
|
|
||||||
->get();
|
|
||||||
foreach ($port_envs as $port_env) {
|
|
||||||
$service_fqdn = str($port_env->key)->beforeLast('_')->after('SERVICE_FQDN_');
|
|
||||||
$env = EnvironmentVariable::where('resourceable_type', Service::class)
|
|
||||||
->where('resourceable_id', $resource->service_id)
|
|
||||||
->where('key', 'SERVICE_FQDN_'.$service_fqdn)
|
|
||||||
->first();
|
|
||||||
if ($env) {
|
|
||||||
if ($path === '/') {
|
|
||||||
$env->value = $host;
|
|
||||||
} else {
|
|
||||||
$env->value = $host.$path;
|
|
||||||
}
|
|
||||||
$env->save();
|
|
||||||
}
|
|
||||||
if ($path === '/') {
|
|
||||||
$port_env->value = $host;
|
|
||||||
} else {
|
|
||||||
$port_env->value = $host.$path;
|
|
||||||
}
|
|
||||||
$port_env->save();
|
|
||||||
}
|
|
||||||
$port_envs_url = EnvironmentVariable::where('resourceable_type', Service::class)
|
|
||||||
->where('resourceable_id', $resource->service_id)
|
|
||||||
->where('key', 'like', "SERVICE_URL_%_$port")
|
|
||||||
->get();
|
|
||||||
foreach ($port_envs_url as $port_env_url) {
|
|
||||||
$service_url = str($port_env_url->key)->beforeLast('_')->after('SERVICE_URL_');
|
|
||||||
$env = EnvironmentVariable::where('resourceable_type', Service::class)
|
|
||||||
->where('resourceable_id', $resource->service_id)
|
|
||||||
->where('key', 'SERVICE_URL_'.$service_url)
|
|
||||||
->first();
|
|
||||||
if ($env) {
|
|
||||||
if ($path === '/') {
|
|
||||||
$env->value = $url;
|
|
||||||
} else {
|
|
||||||
$env->value = $url.$path;
|
|
||||||
}
|
|
||||||
$env->save();
|
|
||||||
}
|
|
||||||
if ($path === '/') {
|
|
||||||
$port_env_url->value = $url;
|
|
||||||
} else {
|
|
||||||
$port_env_url->value = $url.$path;
|
|
||||||
}
|
|
||||||
$port_env_url->save();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', '_');
|
|
||||||
$generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class)
|
|
||||||
->where('resourceable_id', $resource->service_id)
|
|
||||||
->where('key', $variableName)
|
|
||||||
->first();
|
|
||||||
$fqdn = Url::fromString($fqdn);
|
|
||||||
$fqdn = $fqdn->getScheme().'://'.$fqdn->getHost().$fqdn->getPath();
|
|
||||||
if ($generatedEnv) {
|
|
||||||
$generatedEnv->value = $fqdn;
|
|
||||||
$generatedEnv->save();
|
|
||||||
}
|
|
||||||
$variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '_');
|
|
||||||
$generatedEnv = EnvironmentVariable::where('resourceable_type', Service::class)
|
|
||||||
->where('resourceable_id', $resource->service_id)
|
|
||||||
->where('key', $variableName)
|
|
||||||
->first();
|
|
||||||
$url = Url::fromString($fqdn);
|
|
||||||
$url = $url->getHost().$url->getPath();
|
|
||||||
if ($generatedEnv) {
|
|
||||||
$url = str($fqdn)->after('://');
|
|
||||||
$generatedEnv->value = $url;
|
|
||||||
$generatedEnv->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If FQDN is removed, delete the corresponding environment variables
|
|
||||||
$serviceName = str($resource->name)->upper()->replace('-', '_');
|
|
||||||
EnvironmentVariable::where('resourceable_type', Service::class)
|
|
||||||
->where('resourceable_id', $resource->service_id)
|
|
||||||
->where('key', 'LIKE', "SERVICE_FQDN_{$serviceName}%")
|
|
||||||
->delete();
|
|
||||||
EnvironmentVariable::where('resourceable_type', Service::class)
|
|
||||||
->where('resourceable_id', $resource->service_id)
|
|
||||||
->where('key', 'LIKE', "SERVICE_URL_{$serviceName}%")
|
|
||||||
->delete();
|
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e);
|
return handleError($e);
|
||||||
|
@@ -2918,10 +2918,18 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $preview_id = null): Collection
|
function newParser(Application|Service $resource, int $pull_request_id = 0, ?int $preview_id = null, bool $isOneClick = false): Collection
|
||||||
{
|
{
|
||||||
$isApplication = $resource instanceof Application;
|
$isApplication = $resource instanceof Application;
|
||||||
$isService = $resource instanceof Service;
|
$isService = $resource instanceof Service;
|
||||||
|
if ($isApplication) {
|
||||||
|
return applicationParser($resource, $pull_request_id, $preview_id);
|
||||||
|
}
|
||||||
|
if ($isService) {
|
||||||
|
return serviceParser($resource, $isOneClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
return collect([]);
|
||||||
|
|
||||||
$uuid = data_get($resource, 'uuid');
|
$uuid = data_get($resource, 'uuid');
|
||||||
$compose = data_get($resource, 'docker_compose_raw');
|
$compose = data_get($resource, 'docker_compose_raw');
|
||||||
@@ -3078,6 +3086,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
$fqdn = generateFqdn($server, "$uuid");
|
$fqdn = generateFqdn($server, "$uuid");
|
||||||
}
|
}
|
||||||
} elseif ($isService) {
|
} elseif ($isService) {
|
||||||
|
if ($isOneClick) {
|
||||||
if (blank($savedService->fqdn)) {
|
if (blank($savedService->fqdn)) {
|
||||||
if ($fqdnFor) {
|
if ($fqdnFor) {
|
||||||
$fqdn = generateFqdn($server, "$fqdnFor-$uuid");
|
$fqdn = generateFqdn($server, "$fqdnFor-$uuid");
|
||||||
@@ -3087,6 +3096,16 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
} 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// For services which are not one-click, if no explicit FQDN is set, leave SERVICE_FQDN_ variables empty
|
||||||
|
if (blank($savedService->fqdn)) {
|
||||||
|
$fqdn = '';
|
||||||
|
} else {
|
||||||
|
$fqdn = str($savedService->fqdn)->after('://')->before(':')->prepend(str($savedService->fqdn)->before('://')->append('://'))->value();
|
||||||
|
}
|
||||||
|
ray($fqdn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value && get_class($value) === \Illuminate\Support\Stringable::class && $value->startsWith('/')) {
|
if ($value && get_class($value) === \Illuminate\Support\Stringable::class && $value->startsWith('/')) {
|
||||||
@@ -3141,14 +3160,8 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
$key = str($key);
|
$key = str($key);
|
||||||
$value = replaceVariables($value);
|
$value = replaceVariables($value);
|
||||||
$command = parseCommandFromMagicEnvVariable($key);
|
$command = parseCommandFromMagicEnvVariable($key);
|
||||||
$found = $resource->environment_variables()->where('key', $key->value())->where('resourceable_type', get_class($resource))->where('resourceable_id', $resource->id)->first();
|
|
||||||
if ($found) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($command->value() === 'FQDN') {
|
if ($command->value() === 'FQDN') {
|
||||||
if ($isApplication && $resource->build_pack === 'dockercompose') {
|
if ($isOneClick) {
|
||||||
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('_');
|
||||||
@@ -3163,14 +3176,9 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
'is_build_time' => false,
|
'is_build_time' => false,
|
||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
} elseif ($command->value() === 'URL') {
|
} elseif ($command->value() === 'URL') {
|
||||||
if ($isApplication && $resource->build_pack === 'dockercompose') {
|
if ($isOneClick) {
|
||||||
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('_');
|
||||||
@@ -3186,6 +3194,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
'is_build_time' => false,
|
'is_build_time' => false,
|
||||||
'is_preview' => false,
|
'is_preview' => false,
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$value = generateEnvValue($command, $resource);
|
$value = generateEnvValue($command, $resource);
|
||||||
$resource->environment_variables()->firstOrCreate([
|
$resource->environment_variables()->firstOrCreate([
|
||||||
@@ -3279,12 +3288,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
$applicationFound = ServiceApplication::where('name', $serviceName)->where('image', $image)->where('service_id', $resource->id)->first();
|
$applicationFound = ServiceApplication::where('name', $serviceName)->where('image', $image)->where('service_id', $resource->id)->first();
|
||||||
if ($applicationFound) {
|
if ($applicationFound) {
|
||||||
$savedService = $applicationFound;
|
$savedService = $applicationFound;
|
||||||
// $savedService = ServiceDatabase::firstOrCreate([
|
|
||||||
// 'name' => $applicationFound->name,
|
|
||||||
// 'image' => $applicationFound->image,
|
|
||||||
// 'service_id' => $applicationFound->service_id,
|
|
||||||
// ]);
|
|
||||||
// $applicationFound->delete();
|
|
||||||
} else {
|
} else {
|
||||||
$savedService = ServiceDatabase::firstOrCreate([
|
$savedService = ServiceDatabase::firstOrCreate([
|
||||||
'name' => $serviceName,
|
'name' => $serviceName,
|
||||||
@@ -3550,7 +3553,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
$normalEnvironments = $normalEnvironments->filter(function ($value, $key) {
|
$normalEnvironments = $normalEnvironments->filter(function ($value, $key) {
|
||||||
return ! str($value)->startsWith('SERVICE_');
|
return ! str($value)->startsWith('SERVICE_');
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach ($normalEnvironments as $key => $value) {
|
foreach ($normalEnvironments as $key => $value) {
|
||||||
$key = str($key);
|
$key = str($key);
|
||||||
$value = str($value);
|
$value = str($value);
|
||||||
@@ -3669,6 +3671,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
$fqdns = data_get($domains, "$serviceName.domain");
|
$fqdns = data_get($domains, "$serviceName.domain");
|
||||||
// Generate SERVICE_FQDN & SERVICE_URL for dockercompose
|
// Generate SERVICE_FQDN & SERVICE_URL for dockercompose
|
||||||
if ($resource->build_pack === 'dockercompose') {
|
if ($resource->build_pack === 'dockercompose') {
|
||||||
|
|
||||||
foreach ($domains as $forServiceName => $domain) {
|
foreach ($domains as $forServiceName => $domain) {
|
||||||
$parsedDomain = data_get($domain, 'domain');
|
$parsedDomain = data_get($domain, 'domain');
|
||||||
if (filled($parsedDomain)) {
|
if (filled($parsedDomain)) {
|
||||||
@@ -3731,7 +3734,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
} else {
|
} else {
|
||||||
$fqdns = collect(data_get($savedService, 'fqdns'))->filter();
|
$fqdns = collect(data_get($savedService, 'fqdns'))->filter();
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultLabels = defaultLabels(
|
$defaultLabels = defaultLabels(
|
||||||
id: $resource->id,
|
id: $resource->id,
|
||||||
name: $containerName,
|
name: $containerName,
|
||||||
@@ -3757,7 +3759,6 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
$coolifyEnvironments->put('COOLIFY_FQDN', $urls->implode(','));
|
$coolifyEnvironments->put('COOLIFY_FQDN', $urls->implode(','));
|
||||||
}
|
}
|
||||||
add_coolify_default_environment_variables($resource, $coolifyEnvironments, $resource->environment_variables);
|
add_coolify_default_environment_variables($resource, $coolifyEnvironments, $resource->environment_variables);
|
||||||
|
|
||||||
if ($environment->count() > 0) {
|
if ($environment->count() > 0) {
|
||||||
$environment = $environment->filter(function ($value, $key) {
|
$environment = $environment->filter(function ($value, $key) {
|
||||||
return ! str($key)->startsWith('SERVICE_FQDN_');
|
return ! str($key)->startsWith('SERVICE_FQDN_');
|
||||||
|
Reference in New Issue
Block a user