fix: show real volume names

This commit is contained in:
Andras Bacsai 2023-10-01 20:46:49 +02:00
parent 05f162f4e8
commit ed6af777a4
3 changed files with 21 additions and 13 deletions

View File

@ -11,7 +11,6 @@ class Show extends Component
public LocalPersistentVolume $storage; public LocalPersistentVolume $storage;
public bool $isReadOnly = false; public bool $isReadOnly = false;
public ?string $modalId = null; public ?string $modalId = null;
public ?string $realName = null;
protected $rules = [ protected $rules = [
'storage.name' => 'required|string', 'storage.name' => 'required|string',
@ -26,11 +25,6 @@ class Show extends Component
public function mount() public function mount()
{ {
if ($this->storage->resource_type === 'App\Models\ServiceApplication' || $this->storage->resource_type === 'App\Models\ServiceDatabase') {
$this->realName = "{$this->storage->service->service->uuid}_{$this->storage->name}";
} else {
$this->realName = $this->storage->name;
}
$this->modalId = new Cuid2(7); $this->modalId = new Cuid2(7);
} }

View File

@ -248,7 +248,7 @@ public function parse(bool $isNew = false): Collection
// Collect/create/update volumes // Collect/create/update volumes
if ($serviceVolumes->count() > 0) { if ($serviceVolumes->count() > 0) {
foreach ($serviceVolumes as $volume) { $serviceVolumes = $serviceVolumes->map(function ($volume) use ($savedService, $topLevelVolumes) {
$type = null; $type = null;
$source = null; $source = null;
$target = null; $target = null;
@ -276,10 +276,10 @@ public function parse(bool $isNew = false): Collection
} }
if ($type->value() === 'bind') { if ($type->value() === 'bind') {
if ($source->value() === "/var/run/docker.sock") { if ($source->value() === "/var/run/docker.sock") {
continue; return $volume;
} }
if ($source->value() === '/tmp' || $source->value() === '/tmp/') { if ($source->value() === '/tmp' || $source->value() === '/tmp/') {
continue; return $volume;
} }
LocalFileVolume::updateOrCreate( LocalFileVolume::updateOrCreate(
[ [
@ -297,7 +297,17 @@ public function parse(bool $isNew = false): Collection
] ]
); );
} else if ($type->value() === 'volume') { } else if ($type->value() === 'volume') {
$topLevelVolumes->put($source->value(), null); $slug = Str::slug($source, '-');
$name = "{$savedService->service->uuid}_{$slug}";
if (is_string($volume)) {
$source = Str::of($volume)->before(':');
$target = Str::of($volume)->after(':')->beforeLast(':');
$source = $name;
$volume = "$source:$target";
} else if(is_array($volume)) {
data_set($volume, 'source', $name);
}
$topLevelVolumes->put($name, null);
LocalPersistentVolume::updateOrCreate( LocalPersistentVolume::updateOrCreate(
[ [
'mount_path' => $target, 'mount_path' => $target,
@ -305,7 +315,7 @@ public function parse(bool $isNew = false): Collection
'resource_type' => get_class($savedService) 'resource_type' => get_class($savedService)
], ],
[ [
'name' => Str::slug($source, '-'), 'name' => $name,
'mount_path' => $target, 'mount_path' => $target,
'resource_id' => $savedService->id, 'resource_id' => $savedService->id,
'resource_type' => get_class($savedService) 'resource_type' => get_class($savedService)
@ -313,7 +323,11 @@ public function parse(bool $isNew = false): Collection
); );
} }
$savedService->getFilesFromServer(); $savedService->getFilesFromServer();
} ray($volume);
return $volume;
});
data_set($service, 'volumes', $serviceVolumes->toArray());
} }
// Add env_file with at least .env to the service // Add env_file with at least .env to the service

View File

@ -12,7 +12,7 @@ class="underline" href="{{ Str::of(url()->current())->beforeLast('/') }}#compose
@endonce @endonce
<form wire:submit.prevent='submit' class="flex flex-col gap-2 pt-4 xl:items-end xl:flex-row"> <form wire:submit.prevent='submit' class="flex flex-col gap-2 pt-4 xl:items-end xl:flex-row">
@if ($isReadOnly) @if ($isReadOnly)
<x-forms.input id="realName" label="Volume Name" required readonly /> <x-forms.input id="storage.name" label="Volume Name" required readonly />
<x-forms.input id="storage.host_path" label="Source Path" readonly /> <x-forms.input id="storage.host_path" label="Source Path" readonly />
<x-forms.input id="storage.mount_path" label="Destination Path" required readonly /> <x-forms.input id="storage.mount_path" label="Destination Path" required readonly />
@else @else