Merge pull request #2961 from coollabsio/fixservicesenvparse

v4.0.0-beta.319
This commit is contained in:
Andras Bacsai
2024-07-26 20:28:43 +02:00
committed by GitHub
8 changed files with 1406 additions and 44 deletions

View File

@@ -62,11 +62,15 @@ class Navbar extends Component
public function checkDeployments() public function checkDeployments()
{ {
$activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first(); try {
$status = data_get($activity, 'properties.status'); $activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first();
if ($status === 'queued' || $status === 'in_progress') { $status = data_get($activity, 'properties.status');
$this->isDeploymentProgress = true; if ($status === 'queued' || $status === 'in_progress') {
} else { $this->isDeploymentProgress = true;
} else {
$this->isDeploymentProgress = false;
}
} catch (\Exception $e) {
$this->isDeploymentProgress = false; $this->isDeploymentProgress = false;
} }
} }

View File

@@ -24,6 +24,7 @@ class Show extends Component
public string $type; public string $type;
protected $listeners = [ protected $listeners = [
'refresh' => 'refresh',
'compose_loaded' => '$refresh', 'compose_loaded' => '$refresh',
]; ];
@@ -46,6 +47,12 @@ class Show extends Component
'env.is_shown_once' => 'Shown Once', 'env.is_shown_once' => 'Shown Once',
]; ];
public function refresh()
{
$this->env->refresh();
$this->checkEnvs();
}
public function mount() public function mount()
{ {
if ($this->env->getMorphClass() === 'App\Models\SharedEnvironmentVariable') { if ($this->env->getMorphClass() === 'App\Models\SharedEnvironmentVariable') {

View File

@@ -116,7 +116,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
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('service_id', $resource->service_id)->where('key', 'LIKE', "{$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(); $path = $fqdn->getPath();
@@ -128,14 +128,13 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
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.$path; $generatedEnv->value = $fqdn.$path;
$generatedEnv->save(); $generatedEnv->save();
} }
} }
$variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', ''); $variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '');
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'LIKE', "{$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(); $path = $url->getPath();

View File

@@ -977,6 +977,8 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
$target = str($volume)->after(':')->beforeLast(':'); $target = str($volume)->after(':')->beforeLast(':');
if ($source->startsWith('./') || $source->startsWith('/') || $source->startsWith('~')) { if ($source->startsWith('./') || $source->startsWith('/') || $source->startsWith('~')) {
$type = str('bind'); $type = str('bind');
// By default, we cannot determine if the bind is a directory or not, so we set it to directory
$isDirectory = true;
} else { } else {
$type = str('volume'); $type = str('volume');
} }
@@ -985,14 +987,19 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
$source = data_get_str($volume, 'source'); $source = data_get_str($volume, 'source');
$target = data_get_str($volume, 'target'); $target = data_get_str($volume, 'target');
$content = data_get($volume, 'content'); $content = data_get($volume, 'content');
$isDirectory = (bool) data_get($volume, 'isDirectory', false) || (bool) data_get($volume, 'is_directory', false); $isDirectory = (bool) data_get($volume, 'isDirectory', null) || (bool) data_get($volume, 'is_directory', null);
$foundConfig = $savedService->fileStorages()->whereMountPath($target)->first(); $foundConfig = $savedService->fileStorages()->whereMountPath($target)->first();
if ($foundConfig) { if ($foundConfig) {
$contentNotNull = data_get($foundConfig, 'content'); $contentNotNull = data_get($foundConfig, 'content');
if ($contentNotNull) { if ($contentNotNull) {
$content = $contentNotNull; $content = $contentNotNull;
} }
$isDirectory = (bool) data_get($volume, 'isDirectory', false) || (bool) data_get($volume, 'is_directory', false); $isDirectory = (bool) data_get($volume, 'isDirectory', null) || (bool) data_get($volume, 'is_directory', null);
}
if (is_null($isDirectory) && is_null($content)) {
// if isDirectory is not set & content is also not set, we assume it is a directory
ray('setting isDirectory to true');
$isDirectory = true;
} }
} }
if ($type?->value() === 'bind') { if ($type?->value() === 'bind') {
@@ -1058,30 +1065,26 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
data_set($service, 'volumes', $serviceVolumes->toArray()); data_set($service, 'volumes', $serviceVolumes->toArray());
} }
// Add env_file with at least .env to the service
// $envFile = collect(data_get($service, 'env_file', []));
// if ($envFile->count() > 0) {
// if (!$envFile->contains('.env')) {
// $envFile->push('.env');
// }
// } else {
// $envFile = collect(['.env']);
// }
// data_set($service, 'env_file', $envFile->toArray());
// Get variables from the service // Get variables from the service
foreach ($serviceVariables as $variableName => $variable) { foreach ($serviceVariables as $variableName => $variable) {
if (is_numeric($variableName)) { if (is_numeric($variableName)) {
$variable = str($variable); if (is_array($variable)) {
if ($variable->contains('=')) { // - SESSION_SECRET: 123
// - SESSION_SECRET=123 // - SESSION_SECRET:
// - SESSION_SECRET= $key = str(collect($variable)->keys()->first());
$key = $variable->before('='); $value = str(collect($variable)->values()->first());
$value = $variable->after('=');
} else { } else {
// - SESSION_SECRET $variable = str($variable);
$key = $variable; if ($variable->contains('=')) {
$value = null; // - SESSION_SECRET=123
// - SESSION_SECRET=
$key = $variable->before('=');
$value = $variable->after('=');
} else {
// - SESSION_SECRET
$key = $variable;
$value = null;
}
} }
} else { } else {
// SESSION_SECRET: 123 // SESSION_SECRET: 123
@@ -1837,16 +1840,23 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
// Get variables from the service // Get variables from the service
foreach ($serviceVariables as $variableName => $variable) { foreach ($serviceVariables as $variableName => $variable) {
if (is_numeric($variableName)) { if (is_numeric($variableName)) {
$variable = str($variable); if (is_array($variable)) {
if ($variable->contains('=')) { // - SESSION_SECRET: 123
// - SESSION_SECRET=123 // - SESSION_SECRET:
// - SESSION_SECRET= $key = str(collect($variable)->keys()->first());
$key = $variable->before('='); $value = str(collect($variable)->values()->first());
$value = $variable->after('=');
} else { } else {
// - SESSION_SECRET $variable = str($variable);
$key = $variable; if ($variable->contains('=')) {
$value = null; // - SESSION_SECRET=123
// - SESSION_SECRET=
$key = $variable->before('=');
$value = $variable->after('=');
} else {
// - SESSION_SECRET
$key = $variable;
$value = null;
}
} }
} else { } else {
// SESSION_SECRET: 123 // SESSION_SECRET: 123

View File

@@ -7,7 +7,7 @@ return [
// The release version of your application // The release version of your application
// Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD'))
'release' => '4.0.0-beta.318', 'release' => '4.0.0-beta.319',
// When left empty or `null` the Laravel environment will be used // When left empty or `null` the Laravel environment will be used
'environment' => config('app.env'), 'environment' => config('app.env'),

View File

@@ -1,3 +1,3 @@
<?php <?php
return '4.0.0-beta.318'; return '4.0.0-beta.319';

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
{ {
"coolify": { "coolify": {
"v4": { "v4": {
"version": "4.0.0-beta.318" "version": "4.0.0-beta.319"
} }
} }
} }