From 4f77bd43472335403814efc87579330092f7b022 Mon Sep 17 00:00:00 2001 From: Trung-DV Date: Tue, 5 Aug 2025 15:20:22 +0700 Subject: [PATCH 1/3] Fix volume target, use the last part Signed-off-by: Trung-DV --- bootstrap/helpers/shared.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 7ce511f2c..a6b8fe55b 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -3420,7 +3420,7 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int } if (is_string($volume)) { $source = str($volume)->before(':'); - $target = str($volume)->after(':')->beforeLast(':'); + $target = str($volume)->afterLast(':'); $source = $name; $volume = "$source:$target"; } elseif (is_array($volume)) { From 1675c85d4de746ecb7abade86d5f1bfa15764e94 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Sun, 17 Aug 2025 18:09:59 +0200 Subject: [PATCH 2/3] refactor(shared helpers): remove unused parseServiceVolumes function to clean up codebase --- bootstrap/helpers/shared.php | 137 ----------------------------------- 1 file changed, 137 deletions(-) diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index c342244fc..23393a4a4 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -1326,143 +1326,6 @@ function customApiValidator(Collection|array $item, array $rules) 'required' => 'This field is required.', ]); } - -function parseServiceVolumes($serviceVolumes, $resource, $topLevelVolumes, $pull_request_id = 0) -{ - $serviceVolumes = $serviceVolumes->map(function ($volume) use ($resource, $topLevelVolumes, $pull_request_id) { - $type = null; - $source = null; - $target = null; - $content = null; - $isDirectory = false; - if (is_string($volume)) { - $source = str($volume)->before(':'); - $target = str($volume)->after(':')->beforeLast(':'); - $foundConfig = $resource->fileStorages()->whereMountPath($target)->first(); - if ($source->startsWith('./') || $source->startsWith('/') || $source->startsWith('~')) { - $type = str('bind'); - if ($foundConfig) { - $contentNotNull = data_get($foundConfig, 'content'); - if ($contentNotNull) { - $content = $contentNotNull; - } - $isDirectory = data_get($foundConfig, 'is_directory'); - } else { - // By default, we cannot determine if the bind is a directory or not, so we set it to directory - $isDirectory = true; - } - } else { - $type = str('volume'); - } - } elseif (is_array($volume)) { - $type = data_get_str($volume, 'type'); - $source = data_get_str($volume, 'source'); - $target = data_get_str($volume, 'target'); - $content = data_get($volume, 'content'); - $isDirectory = (bool) data_get($volume, 'isDirectory', null) || (bool) data_get($volume, 'is_directory', null); - $foundConfig = $resource->fileStorages()->whereMountPath($target)->first(); - if ($foundConfig) { - $contentNotNull = data_get($foundConfig, 'content'); - if ($contentNotNull) { - $content = $contentNotNull; - } - $isDirectory = data_get($foundConfig, 'is_directory'); - } else { - $isDirectory = (bool) data_get($volume, 'isDirectory', null) || (bool) data_get($volume, 'is_directory', null); - if ((is_null($isDirectory) || ! $isDirectory) && is_null($content)) { - // if isDirectory is not set (or false) & content is also not set, we assume it is a directory - $isDirectory = true; - } - } - } - if ($type?->value() === 'bind') { - if ($source->value() === '/var/run/docker.sock') { - return $volume; - } - if ($source->value() === '/tmp' || $source->value() === '/tmp/') { - return $volume; - } - if (get_class($resource) === \App\Models\Application::class) { - $dir = base_configuration_dir().'/applications/'.$resource->uuid; - } else { - $dir = base_configuration_dir().'/services/'.$resource->service->uuid; - } - - if ($source->startsWith('.')) { - $source = $source->replaceFirst('.', $dir); - } - if ($source->startsWith('~')) { - $source = $source->replaceFirst('~', $dir); - } - if ($pull_request_id !== 0) { - $source = $source."-pr-$pull_request_id"; - } - if (! $resource?->settings?->is_preserve_repository_enabled || $foundConfig?->is_based_on_git) { - LocalFileVolume::updateOrCreate( - [ - 'mount_path' => $target, - 'resource_id' => $resource->id, - 'resource_type' => get_class($resource), - ], - [ - 'fs_path' => $source, - 'mount_path' => $target, - 'content' => $content, - 'is_directory' => $isDirectory, - 'resource_id' => $resource->id, - 'resource_type' => get_class($resource), - ] - ); - } - } elseif ($type->value() === 'volume') { - if ($topLevelVolumes->has($source->value())) { - $v = $topLevelVolumes->get($source->value()); - if (data_get($v, 'driver_opts.type') === 'cifs') { - return $volume; - } - } - $slugWithoutUuid = Str::slug($source, '-'); - if (get_class($resource) === \App\Models\Application::class) { - $name = "{$resource->uuid}_{$slugWithoutUuid}"; - } else { - $name = "{$resource->service->uuid}_{$slugWithoutUuid}"; - } - if (is_string($volume)) { - $source = str($volume)->before(':'); - $target = str($volume)->after(':')->beforeLast(':'); - $source = $name; - $volume = "$source:$target"; - } elseif (is_array($volume)) { - data_set($volume, 'source', $name); - } - $topLevelVolumes->put($name, [ - 'name' => $name, - ]); - LocalPersistentVolume::updateOrCreate( - [ - 'mount_path' => $target, - 'resource_id' => $resource->id, - 'resource_type' => get_class($resource), - ], - [ - 'name' => $name, - 'mount_path' => $target, - 'resource_id' => $resource->id, - 'resource_type' => get_class($resource), - ] - ); - } - dispatch(new ServerFilesFromServerJob($resource)); - - return $volume; - }); - - return [ - 'serviceVolumes' => $serviceVolumes, - 'topLevelVolumes' => $topLevelVolumes, - ]; -} - function parseDockerComposeFile(Service|Application $resource, bool $isNew = false, int $pull_request_id = 0, ?int $preview_id = null) { if ($resource->getMorphClass() === \App\Models\Service::class) { From be34c0c2b4de256ae3c48e27aea68bc64db6312f Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Sun, 17 Aug 2025 18:36:28 +0200 Subject: [PATCH 3/3] refactor(parsers): update volume parsing logic to use beforeLast and afterLast for improved accuracy --- bootstrap/helpers/parsers.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bootstrap/helpers/parsers.php b/bootstrap/helpers/parsers.php index 09898935b..310d71c5d 100644 --- a/bootstrap/helpers/parsers.php +++ b/bootstrap/helpers/parsers.php @@ -304,8 +304,8 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int $content = null; $isDirectory = false; if (is_string($volume)) { - $source = str($volume)->before(':'); - $target = str($volume)->after(':')->beforeLast(':'); + $source = str($volume)->beforeLast(':'); + $target = str($volume)->afterLast(':'); $foundConfig = $fileStorages->whereMountPath($target)->first(); if (sourceIsLocal($source)) { $type = str('bind'); @@ -399,8 +399,8 @@ function applicationParser(Application $resource, int $pull_request_id = 0, ?int $name = "{$name}-pr-$pullRequestId"; } if (is_string($volume)) { - $source = str($volume)->before(':'); - $target = str($volume)->after(':')->beforeLast(':'); + $source = str($volume)->beforeLast(':'); + $target = str($volume)->afterLast(':'); $source = $name; $volume = "$source:$target"; } elseif (is_array($volume)) { @@ -1306,8 +1306,8 @@ function serviceParser(Service $resource): Collection $content = null; $isDirectory = false; if (is_string($volume)) { - $source = str($volume)->before(':'); - $target = str($volume)->after(':')->beforeLast(':'); + $source = str($volume)->beforeLast(':'); + $target = str($volume)->afterLast(':'); $foundConfig = $fileStorages->whereMountPath($target)->first(); if (sourceIsLocal($source)) { $type = str('bind'); @@ -1395,8 +1395,8 @@ function serviceParser(Service $resource): Collection $name = "{$uuid}_{$slugWithoutUuid}"; if (is_string($volume)) { - $source = str($volume)->before(':'); - $target = str($volume)->after(':')->beforeLast(':'); + $source = str($volume)->beforeLast(':'); + $target = str($volume)->afterLast(':'); $source = $name; $volume = "$source:$target"; } elseif (is_array($volume)) {