Skip to content

Commit 10b9c4b

Browse files
authored
Merge pull request coollabsio#2961 from coollabsio/fixservicesenvparse
v4.0.0-beta.319
2 parents f76d45b + 38d9140 commit 10b9c4b

File tree

8 files changed

+1406
-44
lines changed

8 files changed

+1406
-44
lines changed

app/Livewire/Project/Service/Navbar.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ public function render()
6262

6363
public function checkDeployments()
6464
{
65-
$activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first();
66-
$status = data_get($activity, 'properties.status');
67-
if ($status === 'queued' || $status === 'in_progress') {
68-
$this->isDeploymentProgress = true;
69-
} else {
65+
try {
66+
$activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first();
67+
$status = data_get($activity, 'properties.status');
68+
if ($status === 'queued' || $status === 'in_progress') {
69+
$this->isDeploymentProgress = true;
70+
} else {
71+
$this->isDeploymentProgress = false;
72+
}
73+
} catch (\Exception $e) {
7074
$this->isDeploymentProgress = false;
7175
}
7276
}

app/Livewire/Project/Shared/EnvironmentVariable/Show.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Show extends Component
2424
public string $type;
2525

2626
protected $listeners = [
27+
'refresh' => 'refresh',
2728
'compose_loaded' => '$refresh',
2829
];
2930

@@ -46,6 +47,12 @@ class Show extends Component
4647
'env.is_shown_once' => 'Shown Once',
4748
];
4849

50+
public function refresh()
51+
{
52+
$this->env->refresh();
53+
$this->checkEnvs();
54+
}
55+
4956
public function mount()
5057
{
5158
if ($this->env->getMorphClass() === 'App\Models\SharedEnvironmentVariable') {

bootstrap/helpers/services.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
116116
if ($resourceFqdns->count() === 1) {
117117
$resourceFqdns = $resourceFqdns->first();
118118
$variableName = 'SERVICE_FQDN_'.str($resource->name)->upper()->replace('-', '');
119-
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'LIKE', "{$variableName}_%")->first();
119+
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
120120
$fqdn = Url::fromString($resourceFqdns);
121121
$port = $fqdn->getPort();
122122
$path = $fqdn->getPath();
@@ -128,14 +128,13 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
128128
if ($port) {
129129
$variableName = $variableName."_$port";
130130
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
131-
// ray($generatedEnv);
132131
if ($generatedEnv) {
133132
$generatedEnv->value = $fqdn.$path;
134133
$generatedEnv->save();
135134
}
136135
}
137136
$variableName = 'SERVICE_URL_'.str($resource->name)->upper()->replace('-', '');
138-
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', 'LIKE', "{$variableName}_%")->first();
137+
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
139138
$url = Url::fromString($fqdn);
140139
$port = $url->getPort();
141140
$path = $url->getPath();

bootstrap/helpers/shared.php

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,8 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
977977
$target = str($volume)->after(':')->beforeLast(':');
978978
if ($source->startsWith('./') || $source->startsWith('/') || $source->startsWith('~')) {
979979
$type = str('bind');
980+
// By default, we cannot determine if the bind is a directory or not, so we set it to directory
981+
$isDirectory = true;
980982
} else {
981983
$type = str('volume');
982984
}
@@ -985,14 +987,19 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
985987
$source = data_get_str($volume, 'source');
986988
$target = data_get_str($volume, 'target');
987989
$content = data_get($volume, 'content');
988-
$isDirectory = (bool) data_get($volume, 'isDirectory', false) || (bool) data_get($volume, 'is_directory', false);
990+
$isDirectory = (bool) data_get($volume, 'isDirectory', null) || (bool) data_get($volume, 'is_directory', null);
989991
$foundConfig = $savedService->fileStorages()->whereMountPath($target)->first();
990992
if ($foundConfig) {
991993
$contentNotNull = data_get($foundConfig, 'content');
992994
if ($contentNotNull) {
993995
$content = $contentNotNull;
994996
}
995-
$isDirectory = (bool) data_get($volume, 'isDirectory', false) || (bool) data_get($volume, 'is_directory', false);
997+
$isDirectory = (bool) data_get($volume, 'isDirectory', null) || (bool) data_get($volume, 'is_directory', null);
998+
}
999+
if (is_null($isDirectory) && is_null($content)) {
1000+
// if isDirectory is not set & content is also not set, we assume it is a directory
1001+
ray('setting isDirectory to true');
1002+
$isDirectory = true;
9961003
}
9971004
}
9981005
if ($type?->value() === 'bind') {
@@ -1058,30 +1065,26 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
10581065
data_set($service, 'volumes', $serviceVolumes->toArray());
10591066
}
10601067

1061-
// Add env_file with at least .env to the service
1062-
// $envFile = collect(data_get($service, 'env_file', []));
1063-
// if ($envFile->count() > 0) {
1064-
// if (!$envFile->contains('.env')) {
1065-
// $envFile->push('.env');
1066-
// }
1067-
// } else {
1068-
// $envFile = collect(['.env']);
1069-
// }
1070-
// data_set($service, 'env_file', $envFile->toArray());
1071-
10721068
// Get variables from the service
10731069
foreach ($serviceVariables as $variableName => $variable) {
10741070
if (is_numeric($variableName)) {
1075-
$variable = str($variable);
1076-
if ($variable->contains('=')) {
1077-
// - SESSION_SECRET=123
1078-
// - SESSION_SECRET=
1079-
$key = $variable->before('=');
1080-
$value = $variable->after('=');
1071+
if (is_array($variable)) {
1072+
// - SESSION_SECRET: 123
1073+
// - SESSION_SECRET:
1074+
$key = str(collect($variable)->keys()->first());
1075+
$value = str(collect($variable)->values()->first());
10811076
} else {
1082-
// - SESSION_SECRET
1083-
$key = $variable;
1084-
$value = null;
1077+
$variable = str($variable);
1078+
if ($variable->contains('=')) {
1079+
// - SESSION_SECRET=123
1080+
// - SESSION_SECRET=
1081+
$key = $variable->before('=');
1082+
$value = $variable->after('=');
1083+
} else {
1084+
// - SESSION_SECRET
1085+
$key = $variable;
1086+
$value = null;
1087+
}
10851088
}
10861089
} else {
10871090
// SESSION_SECRET: 123
@@ -1837,16 +1840,23 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
18371840
// Get variables from the service
18381841
foreach ($serviceVariables as $variableName => $variable) {
18391842
if (is_numeric($variableName)) {
1840-
$variable = str($variable);
1841-
if ($variable->contains('=')) {
1842-
// - SESSION_SECRET=123
1843-
// - SESSION_SECRET=
1844-
$key = $variable->before('=');
1845-
$value = $variable->after('=');
1843+
if (is_array($variable)) {
1844+
// - SESSION_SECRET: 123
1845+
// - SESSION_SECRET:
1846+
$key = str(collect($variable)->keys()->first());
1847+
$value = str(collect($variable)->values()->first());
18461848
} else {
1847-
// - SESSION_SECRET
1848-
$key = $variable;
1849-
$value = null;
1849+
$variable = str($variable);
1850+
if ($variable->contains('=')) {
1851+
// - SESSION_SECRET=123
1852+
// - SESSION_SECRET=
1853+
$key = $variable->before('=');
1854+
$value = $variable->after('=');
1855+
} else {
1856+
// - SESSION_SECRET
1857+
$key = $variable;
1858+
$value = null;
1859+
}
18501860
}
18511861
} else {
18521862
// SESSION_SECRET: 123

config/sentry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

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

config/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
return '4.0.0-beta.318';
3+
return '4.0.0-beta.319';

templates/service-templates.json

Lines changed: 1343 additions & 1 deletion
Large diffs are not rendered by default.

versions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"coolify": {
33
"v4": {
4-
"version": "4.0.0-beta.318"
4+
"version": "4.0.0-beta.319"
55
}
66
}
7-
}
7+
}

0 commit comments

Comments
 (0)