diff --git a/app/Http/Livewire/Project/Service/Index.php b/app/Http/Livewire/Project/Service/Index.php index 18029fb73..3f48fdf5d 100644 --- a/app/Http/Livewire/Project/Service/Index.php +++ b/app/Http/Livewire/Project/Service/Index.php @@ -29,7 +29,10 @@ public function mount() $this->parameters = get_route_parameters(); $this->query = request()->query(); $this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail(); - $this->refreshStack(); + $this->applications = $this->service->applications->sort(); + $this->databases = $this->service->databases->sort(); + ray($this->applications); + ray($this->databases); } public function saveCompose($raw) { diff --git a/app/Http/Livewire/Project/Service/Storage.php b/app/Http/Livewire/Project/Service/Storage.php new file mode 100644 index 000000000..2e3ef8f58 --- /dev/null +++ b/app/Http/Livewire/Project/Service/Storage.php @@ -0,0 +1,35 @@ + $data['name'], + 'mount_path' => $data['mount_path'], + 'host_path' => $data['host_path'], + 'resource_id' => $this->resource->id, + 'resource_type' => $this->resource->getMorphClass(), + ]); + $this->resource->refresh(); + $this->emit('success', 'Storage added successfully'); + $this->emit('clearAddStorage'); + $this->emit('refreshStorages'); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } +} diff --git a/app/Http/Livewire/Project/Shared/Storages/Add.php b/app/Http/Livewire/Project/Shared/Storages/Add.php index 1edfe03a4..7278eda7a 100644 --- a/app/Http/Livewire/Project/Shared/Storages/Add.php +++ b/app/Http/Livewire/Project/Shared/Storages/Add.php @@ -33,7 +33,7 @@ public function submit() { $this->validate(); $name = $this->uuid . '-' . $this->name; - $this->emitUp('submit', [ + $this->emit('addNewVolume', [ 'name' => $name, 'mount_path' => $this->mount_path, 'host_path' => $this->host_path, diff --git a/app/Http/Livewire/Project/Shared/Storages/All.php b/app/Http/Livewire/Project/Shared/Storages/All.php index 8ac22d881..457071711 100644 --- a/app/Http/Livewire/Project/Shared/Storages/All.php +++ b/app/Http/Livewire/Project/Shared/Storages/All.php @@ -7,30 +7,11 @@ class All extends Component { - public bool $isHeaderVisible = true; public $resource; - protected $listeners = ['refreshStorages', 'submit']; + protected $listeners = ['refreshStorages']; public function refreshStorages() { $this->resource->refresh(); } - - public function submit($data) - { - try { - LocalPersistentVolume::create([ - 'name' => $data['name'], - 'mount_path' => $data['mount_path'], - 'host_path' => $data['host_path'], - 'resource_id' => $this->resource->id, - 'resource_type' => $this->resource->getMorphClass(), - ]); - $this->resource->refresh(); - $this->emit('success', 'Storage added successfully'); - $this->emit('clearAddStorage'); - } catch (\Throwable $e) { - return handleError($e, $this); - } - } } diff --git a/app/Models/Application.php b/app/Models/Application.php index fc437769a..af2db98ee 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -44,6 +44,10 @@ public function persistentStorages() { return $this->morphMany(LocalPersistentVolume::class, 'resource'); } + public function fileStorages() + { + return $this->morphMany(LocalFileVolume::class, 'resource'); + } public function type() { diff --git a/app/Models/LocalFileVolume.php b/app/Models/LocalFileVolume.php index b45a868aa..f426e40a0 100644 --- a/app/Models/LocalFileVolume.php +++ b/app/Models/LocalFileVolume.php @@ -31,23 +31,18 @@ public function saveStorageOnServer(ServiceApplication|ServiceDatabase $service) } $isFile = instant_remote_process(["test -f $path && echo OK || echo NOK"], $server); $isDir = instant_remote_process(["test -d $path && echo OK || echo NOK"], $server); - ray($isFile); if ($isFile == 'OK' && $fileVolume->is_directory) { throw new \Exception("File $path is a file on the server, but you are trying to mark it as a directory. Please delete the file on the server or mark it as directory."); } else if ($isDir == 'OK' && !$fileVolume->is_directory) { throw new \Exception("File $path is a directory on the server, but you are trying to mark it as a file. Please delete the directory on the server or mark it as directory."); } - if (($isFile == 'NOK' && !$fileVolume->is_directory) || $isFile == 'OK') { - $rootDir = Str::of($path)->dirname(); - $commands->push("mkdir -p $rootDir > /dev/null 2>&1 || true"); - $commands->push("touch $path > /dev/null 2>&1 || true"); - if ($content) { - $content = base64_encode($content); - $commands->push("echo '$content' | base64 -d > $path"); - } - } else if ($isDir == 'NOK' && $fileVolume->is_directory) { + if (!$fileVolume->is_directory && $isDir == 'NOK') { + $content = base64_encode($content); + $commands->push("echo '$content' | base64 -d > $path"); + } else if ($isDir == 'NOK' && $fileVolume->is_directory) { $commands->push("mkdir -p $path > /dev/null 2>&1 || true"); } + ray($commands->toArray()); return instant_remote_process($commands, $server); } } diff --git a/app/Models/StandalonePostgresql.php b/app/Models/StandalonePostgresql.php index 17b5b8056..ed270862b 100644 --- a/app/Models/StandalonePostgresql.php +++ b/app/Models/StandalonePostgresql.php @@ -76,6 +76,11 @@ public function environment() return $this->belongsTo(Environment::class); } + public function fileStorages() + { + return $this->morphMany(LocalFileVolume::class, 'resource'); + } + public function destination() { return $this->morphTo(); diff --git a/bootstrap/helpers/services.php b/bootstrap/helpers/services.php index 306ca172f..2590049ad 100644 --- a/bootstrap/helpers/services.php +++ b/bootstrap/helpers/services.php @@ -85,28 +85,39 @@ function getFilesystemVolumesFromServer(ServiceApplication|ServiceDatabase $oneS } else { $fileLocation = $path; } + ray($path,$fileLocation); + // Exists and is a file $isFile = instant_remote_process(["test -f $fileLocation && echo OK || echo NOK"], $server); + // Exists and is a directory $isDir = instant_remote_process(["test -d $fileLocation && echo OK || echo NOK"], $server); - if ($isFile === 'NOK' &&!$fileVolume->is_directory && $isInit) { - $fileVolume->saveStorageOnServer($oneService); - continue; - } - if ($isFile == 'OK' && !$fileVolume->is_directory) { + + if ($isFile == 'OK') { + // If its a file & exists $filesystemContent = instant_remote_process(["cat $fileLocation"], $server); - if (base64_encode($filesystemContent) != base64_encode($content)) { - $fileVolume->content = $filesystemContent; - $fileVolume->save(); - } - } else { - if ($isDir == 'OK') { - $fileVolume->content = null; - $fileVolume->is_directory = true; - $fileVolume->save(); - } else { - $fileVolume->content = null; - $fileVolume->is_directory = false; - $fileVolume->save(); - } + $fileVolume->content = $filesystemContent; + $fileVolume->is_directory = false; + $fileVolume->save(); + } else if ($isDir == 'OK') { + // If its a directory & exists + $fileVolume->content = null; + $fileVolume->is_directory = true; + $fileVolume->save(); + } else if ($isFile == 'NOK' && $isDir == 'NOK' && !$fileVolume->is_directory && $isInit && $content) { + // Does not exists (no dir or file), not flagged as directory, is init, has content + $fileVolume->content = $content; + $fileVolume->is_directory = false; + $fileVolume->save(); + $content = base64_encode($content); + $dir = Str::of($fileLocation)->dirname(); + instant_remote_process([ + "mkdir -p $dir", + "echo '$content' | base64 -d > $fileLocation" + ], $server); + } else if ($isFile == 'NOK' && $isDir == 'NOK' && $fileVolume->is_directory && $isInit) { + $fileVolume->content = null; + $fileVolume->is_directory = true; + $fileVolume->save(); + instant_remote_process(["mkdir -p $fileLocation"], $server); } } } catch (\Throwable $e) { diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php index 28a2deb63..dfa0d7d95 100644 --- a/resources/views/livewire/project/service/index.blade.php +++ b/resources/views/livewire/project/service/index.blade.php @@ -1,4 +1,4 @@ -
+
@@ -102,42 +102,18 @@
+
+

Storages

+
+
Persistent storage to preserve data between deployments.
+ Please modify storage layout in your Docker Compose file. @foreach ($applications as $application) - @if ($loop->first) - - @else - - @endif - @if ($application->fileStorages()->get()->count() > 0) -
Mounted Files/Dirs (binds)
-
- @foreach ($application->fileStorages()->get()->sort() as $fileStorage) - - @endforeach -
- @endif + @endforeach @foreach ($databases as $database) - @if ($loop->first) -

{{ Str::headline($database->name) }}

- @if ($applications->count() > 0) - - @else - - @endif - @if ($database->fileStorages()->get()->count() > 0) -
Mounted Files/Dirs (binds)
-
- @foreach ($database->fileStorages()->get()->sort() as $fileStorage) - - @endforeach -
- @endif - @else - - @endif + @endforeach
diff --git a/resources/views/livewire/project/service/show.blade.php b/resources/views/livewire/project/service/show.blade.php index b789e6550..07f206c80 100644 --- a/resources/views/livewire/project/service/show.blade.php +++ b/resources/views/livewire/project/service/show.blade.php @@ -24,15 +24,14 @@
- - @if ($serviceApplication->fileStorages()->get()->count() > 0) -
Mounted Files/Dirs (binds)
-
- @foreach ($serviceApplication->fileStorages()->get()->sort() as $fileStorage) - - @endforeach -
- @endif +
+

Storages

+
+
Persistent storage to preserve data between deployments.
+ Please modify storage layout in your Docker Compose file. +
@endisset @isset($serviceDatabase) @@ -40,15 +39,14 @@
- - @if ($serviceDatabase->fileStorages()->get()->count() > 0) -
Mounted Files/Dirs (binds)
-
- @foreach ($serviceDatabase->fileStorages()->get()->sort() as $fileStorage) - - @endforeach -
- @endif +
+

Storages

+
+
Persistent storage to preserve data between deployments.
+ Please modify storage layout in your Docker Compose file. +
@endisset diff --git a/resources/views/livewire/project/service/storage.blade.php b/resources/views/livewire/project/service/storage.blade.php new file mode 100644 index 000000000..97a089cf8 --- /dev/null +++ b/resources/views/livewire/project/service/storage.blade.php @@ -0,0 +1,49 @@ +
+ @if ( + $resource->getMorphClass() == 'App\Models\Application' || + $resource->getMorphClass() == 'App\Models\StandalonePostgresql') +
+

Storages

+ + + Add + +
+
Persistent storage to preserve data between deployments.
+ @if ( + $resource->persistentStorages()->get()->count() === 0 && + $resource->fileStorages()->get()->count() == 0) +
No storage found.
+ @else + @if ($resource->persistentStorages()->get()->count() > 0) + + @endif + @if ($resource->fileStorages()->get()->count() > 0) +
+ @foreach ($resource->fileStorages()->get()->sort() as $fileStorage) + + @endforeach +
+ @endif + @endif + @else + @if ( + $resource->persistentStorages()->get()->count() > 0 || + $resource->fileStorages()->get()->count() > 0) +

{{ Str::headline($resource->name) }}

+ @endif + @if ($resource->persistentStorages()->get()->count() > 0) + + @endif + @if ($resource->fileStorages()->get()->count() > 0) +
+ @foreach ($resource->fileStorages()->get()->sort() as $fileStorage) + + @endforeach +
+ @endif + @endif +
diff --git a/resources/views/livewire/project/shared/storages/all.blade.php b/resources/views/livewire/project/shared/storages/all.blade.php index fbf8cd593..dfd2064dc 100644 --- a/resources/views/livewire/project/shared/storages/all.blade.php +++ b/resources/views/livewire/project/shared/storages/all.blade.php @@ -1,25 +1,4 @@
- @if ($isHeaderVisible) -
-
-

Storages

- @if ($resource->type() !== 'service') - - + Add - - @endif -
-
Persistent storage to preserve data between deployments.
- @if ($resource->type() === 'service') - Please modify storage layout in your Docker Compose file. -

{{ Str::headline($resource->name) }}

- @endif -
- @endif
@foreach ($resource->persistentStorages as $storage) @if ($resource->type() === 'service') diff --git a/resources/views/project/application/configuration.blade.php b/resources/views/project/application/configuration.blade.php index 6d8971c8f..78f0a3061 100644 --- a/resources/views/project/application/configuration.blade.php +++ b/resources/views/project/application/configuration.blade.php @@ -14,8 +14,7 @@ @click.prevent="activeTab = 'source'; window.location.hash = 'source'" href="#">Source @endif Server + @click.prevent="activeTab = 'server'; window.location.hash = 'server'" href="#">Server Storages @@ -27,8 +26,8 @@ @endif Health Checks - + @click.prevent="activeTab = 'health'; window.location.hash = 'health'" href="#">Health Checks + Rollback @@ -56,7 +55,7 @@
- +
diff --git a/resources/views/project/database/configuration.blade.php b/resources/views/project/database/configuration.blade.php index 5c16a0050..78daa3b0c 100644 --- a/resources/views/project/database/configuration.blade.php +++ b/resources/views/project/database/configuration.blade.php @@ -47,7 +47,7 @@
- +