fix(file-storage): double save on compose volumes
This commit is contained in:
@@ -176,4 +176,19 @@ class LocalFileVolume extends BaseModel
|
|||||||
|
|
||||||
return instant_remote_process($commands, $server);
|
return 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1363,21 +1363,15 @@ function parseServiceVolumes($serviceVolumes, $resource, $topLevelVolumes, $pull
|
|||||||
$source = $source."-pr-$pull_request_id";
|
$source = $source."-pr-$pull_request_id";
|
||||||
}
|
}
|
||||||
if (! $resource?->settings?->is_preserve_repository_enabled || $foundConfig?->is_based_on_git) {
|
if (! $resource?->settings?->is_preserve_repository_enabled || $foundConfig?->is_based_on_git) {
|
||||||
LocalFileVolume::updateOrCreate(
|
$volume = LocalFileVolume::wherePlainMountPath($target)->first() ?? new LocalFileVolume;
|
||||||
[
|
$volume->fill([
|
||||||
'mount_path' => $target,
|
|
||||||
'resource_id' => $resource->id,
|
|
||||||
'resource_type' => get_class($resource),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'fs_path' => $source,
|
'fs_path' => $source,
|
||||||
'mount_path' => $target,
|
'mount_path' => $target,
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'is_directory' => $isDirectory,
|
'is_directory' => $isDirectory,
|
||||||
'resource_id' => $resource->id,
|
'resource_id' => $resource->id,
|
||||||
'resource_type' => get_class($resource),
|
'resource_type' => get_class($resource),
|
||||||
]
|
])->save();
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} elseif ($type->value() === 'volume') {
|
} elseif ($type->value() === 'volume') {
|
||||||
if ($topLevelVolumes->has($source->value())) {
|
if ($topLevelVolumes->has($source->value())) {
|
||||||
@@ -1675,21 +1669,28 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal
|
|||||||
if ($source->value() === '/tmp' || $source->value() === '/tmp/') {
|
if ($source->value() === '/tmp' || $source->value() === '/tmp/') {
|
||||||
return $volume;
|
return $volume;
|
||||||
}
|
}
|
||||||
LocalFileVolume::updateOrCreate(
|
|
||||||
[
|
$existingVolume = LocalFileVolume::wherePlainMountPath($target)->first();
|
||||||
'mount_path' => $target,
|
|
||||||
'resource_id' => $savedService->id,
|
if ($existingVolume) {
|
||||||
'resource_type' => get_class($savedService),
|
$existingVolume->update([
|
||||||
],
|
|
||||||
[
|
|
||||||
'fs_path' => $source,
|
'fs_path' => $source,
|
||||||
'mount_path' => $target,
|
'mount_path' => $target,
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'is_directory' => $isDirectory,
|
'is_directory' => $isDirectory,
|
||||||
'resource_id' => $savedService->id,
|
'resource_id' => $savedService->id,
|
||||||
'resource_type' => get_class($savedService),
|
'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') {
|
} elseif ($type->value() === 'volume') {
|
||||||
if ($topLevelVolumes->has($source->value())) {
|
if ($topLevelVolumes->has($source->value())) {
|
||||||
$v = $topLevelVolumes->get($source->value());
|
$v = $topLevelVolumes->get($source->value());
|
||||||
@@ -3327,21 +3328,15 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
|
|||||||
if ($isApplication && $isPullRequest) {
|
if ($isApplication && $isPullRequest) {
|
||||||
$source = $source."-pr-$pullRequestId";
|
$source = $source."-pr-$pullRequestId";
|
||||||
}
|
}
|
||||||
LocalFileVolume::updateOrCreate(
|
$volume = LocalFileVolume::wherePlainMountPath($target)->first() ?? new LocalFileVolume;
|
||||||
[
|
$volume->fill([
|
||||||
'mount_path' => $target,
|
|
||||||
'resource_id' => $originalResource->id,
|
|
||||||
'resource_type' => get_class($originalResource),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'fs_path' => $source,
|
'fs_path' => $source,
|
||||||
'mount_path' => $target,
|
'mount_path' => $target,
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
'is_directory' => $isDirectory,
|
'is_directory' => $isDirectory,
|
||||||
'resource_id' => $originalResource->id,
|
'resource_id' => $originalResource->id,
|
||||||
'resource_type' => get_class($originalResource),
|
'resource_type' => get_class($originalResource),
|
||||||
]
|
])->save();
|
||||||
);
|
|
||||||
if (isDev()) {
|
if (isDev()) {
|
||||||
if ((int) $resource->compose_parsing_version >= 4) {
|
if ((int) $resource->compose_parsing_version >= 4) {
|
||||||
if ($isApplication) {
|
if ($isApplication) {
|
||||||
|
Reference in New Issue
Block a user