mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-14 02:15:51 +00:00
Improve storage mount path handling
This commit is contained in:
1 parent
39ae16de42
commit
a06c1a7bf5
17 files changed
+979
-55
No files matched your search
@@ -29,6 +29,10 @@ class Storage extends Component
|
||||
|
||||
public ?string $file_storage_content = null;
|
||||
|
||||
public string $host_file_storage_source = '';
|
||||
|
||||
public string $host_file_storage_destination = '';
|
||||
|
||||
public string $file_storage_directory_source = '';
|
||||
|
||||
public string $file_storage_directory_destination = '';
|
||||
@@ -146,19 +150,9 @@ class Storage extends Component
|
||||
'file_storage_content' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$this->file_storage_path = trim($this->file_storage_path);
|
||||
$this->file_storage_path = str($this->file_storage_path)->start('/')->value();
|
||||
$this->file_storage_path = validateFileMountPath($this->file_storage_path, 'file storage path');
|
||||
|
||||
// Validate path to prevent command injection
|
||||
validateShellSafePath($this->file_storage_path, 'file storage path');
|
||||
|
||||
if ($this->resource->getMorphClass() === Application::class) {
|
||||
$fs_path = application_configuration_dir().'/'.$this->resource->uuid.$this->file_storage_path;
|
||||
} elseif (str($this->resource->getMorphClass())->contains('Standalone')) {
|
||||
$fs_path = database_configuration_dir().'/'.$this->resource->uuid.$this->file_storage_path;
|
||||
} else {
|
||||
throw new \Exception('No valid resource type for file mount storage type!');
|
||||
}
|
||||
$fs_path = confineFileMountPath($this->fileStorageHostPath(), $this->file_storage_path, 'file storage path');
|
||||
|
||||
LocalFileVolume::create([
|
||||
'fs_path' => $fs_path,
|
||||
@@ -178,6 +172,38 @@ class Storage extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function submitHostFileStorage()
|
||||
{
|
||||
try {
|
||||
$this->authorize('update', $this->resource);
|
||||
|
||||
$this->validate([
|
||||
'host_file_storage_source' => 'required|string',
|
||||
'host_file_storage_destination' => 'required|string',
|
||||
]);
|
||||
|
||||
$this->host_file_storage_source = validateHostFileMountPath($this->host_file_storage_source, 'host file source path');
|
||||
$this->host_file_storage_destination = validateFileMountPath($this->host_file_storage_destination, 'host file destination path');
|
||||
|
||||
LocalFileVolume::create([
|
||||
'fs_path' => $this->host_file_storage_source,
|
||||
'mount_path' => $this->host_file_storage_destination,
|
||||
'content' => null,
|
||||
'is_directory' => false,
|
||||
'is_host_file' => true,
|
||||
'resource_id' => $this->resource->id,
|
||||
'resource_type' => get_class($this->resource),
|
||||
]);
|
||||
|
||||
$this->dispatch('success', 'Host file mount added successfully');
|
||||
$this->dispatch('closeStorageModal', 'host-file');
|
||||
$this->clearForm();
|
||||
$this->refreshStorages();
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
|
||||
public function submitFileStorageDirectory()
|
||||
{
|
||||
try {
|
||||
@@ -222,6 +248,8 @@ class Storage extends Component
|
||||
$this->file_storage_path = '';
|
||||
$this->file_storage_content = null;
|
||||
$this->file_storage_directory_destination = '';
|
||||
$this->host_file_storage_source = '';
|
||||
$this->host_file_storage_destination = '';
|
||||
|
||||
if (str($this->resource->getMorphClass())->contains('Standalone')) {
|
||||
$this->file_storage_directory_source = database_configuration_dir()."/{$this->resource->uuid}";
|
||||
@@ -230,6 +258,34 @@ class Storage extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function fileStorageHostPath(): string
|
||||
{
|
||||
if (method_exists($this->resource, 'workdir')) {
|
||||
return $this->resource->workdir();
|
||||
}
|
||||
|
||||
if ($this->resource->getMorphClass() === Application::class) {
|
||||
return application_configuration_dir().'/'.$this->resource->uuid;
|
||||
}
|
||||
|
||||
if (str($this->resource->getMorphClass())->contains('Standalone')) {
|
||||
return database_configuration_dir().'/'.$this->resource->uuid;
|
||||
}
|
||||
|
||||
throw new \Exception('No valid resource type for file mount storage type!');
|
||||
}
|
||||
|
||||
public function fileStoragePreviewPath(): string
|
||||
{
|
||||
$path = str($this->file_storage_path)->trim();
|
||||
|
||||
if ($path->isEmpty()) {
|
||||
return $this->fileStorageHostPath().'/';
|
||||
}
|
||||
|
||||
return $this->fileStorageHostPath().$path->start('/')->value();
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.project.service.storage');
|
||||
|
||||
Reference in new issue
Block a user