An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(file-storage): double save on compose volumes
Andras Bacsaic2941abe572f
diff --git a/app/Models/LocalFileVolume.php b/app/Models/LocalFileVolume.phpindex a3bbbc64aa..1a5430c5bc 100644--- a/app/Models/LocalFileVolume.php+++ b/app/Models/LocalFileVolume.php@@ -176,4 +176,19 @@ class LocalFileVolume extends BaseModelreturn instant_remote_process($commands, $server);}++ // Accessor for convenient access+ protected function plainMountPath(): Attribute+ {+ return Attribute::make(+ get: fn () => $this->mount_path,+ set: fn ($value) => $this->mount_path = $value+ );+ }++ // Scope for searching+ public function scopeWherePlainMountPath($query, $path)+ {+ return $query->get()->where('plain_mount_path', $path);+ }}diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex 7dc6365874..218ca1b371 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -1363,21 +1363,15 @@ function parseServiceVolumes($serviceVolumes, $resource, $topLevelVolumes, $pull$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),- ]- );+ $volume = LocalFileVolume::wherePlainMountPath($target)->first() ?? new LocalFileVolume;+ $volume->fill([+ 'fs_path' => $source,+ 'mount_path' => $target,+ 'content' => $content,+ 'is_directory' => $isDirectory,+ 'resource_id' => $resource->id,+ 'resource_type' => get_class($resource),+ ])->save();}} elseif ($type->value() === 'volume') {if ($topLevelVolumes->has($source->value())) {@@ -1675,21 +1669,28 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = falif ($source->value() === '/tmp' || $source->value() === '/tmp/') {return $volume;}- LocalFileVolume::updateOrCreate(- [++ $existingVolume = LocalFileVolume::wherePlainMountPath($target)->first();++ if ($existingVolume) {+ $existingVolume->update([+ 'fs_path' => $source,'mount_path' => $target,+ 'content' => $content,+ 'is_directory' => $isDirectory,'resource_id' => $savedService->id,'resource_type' => get_class($savedService),- ],- [+ ]);+ } else {+ LocalFileVolume::create(['fs_path' => $source,'mount_path' => $target,'content' => $content,'is_directory' => $isDirectory,'resource_id' => $savedService->id,'resource_type' => get_class($savedService),- ]- );+ ]);+ }} elseif ($type->value() === 'volume') {if ($topLevelVolumes->has($source->value())) {$v = $topLevelVolumes->get($source->value());@@ -3327,21 +3328,15 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?intif ($isApplication && $isPullRequest) {$source = $source."-pr-$pullRequestId";}- LocalFileVolume::updateOrCreate(- [- 'mount_path' => $target,- 'resource_id' => $originalResource->id,- 'resource_type' => get_class($originalResource),- ],- [- 'fs_path' => $source,- 'mount_path' => $target,- 'content' => $content,- 'is_directory' => $isDirectory,- 'resource_id' => $originalResource->id,- 'resource_type' => get_class($originalResource),- ]- );+ $volume = LocalFileVolume::wherePlainMountPath($target)->first() ?? new LocalFileVolume;+ $volume->fill([+ 'fs_path' => $source,+ 'mount_path' => $target,+ 'content' => $content,+ 'is_directory' => $isDirectory,+ 'resource_id' => $originalResource->id,+ 'resource_type' => get_class($originalResource),+ ])->save();if (isDev()) {if ((int) $resource->compose_parsing_version >= 4) {if ($isApplication) {