Skip to content

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.

feat: move volume data cloning to a Job

peaklabs-dev5877cead8912
diff --git a/app/Jobs/VolumeCloneJob.php b/app/Jobs/VolumeCloneJob.php
new file mode 100644
index 0000000000..95ac141973
--- /dev/null
+++ b/app/Jobs/VolumeCloneJob.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace App\Jobs;
+
+use App\Models\LocalPersistentVolume;
+use App\Models\Server;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldBeEncrypted;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+
+class VolumeCloneJob implements ShouldBeEncrypted, ShouldQueue
+{
+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+ public function __construct(
+ protected string $sourceVolume,
+ protected string $targetVolume,
+ protected Server $server,
+ protected LocalPersistentVolume $persistentVolume
+ ) {
+ $this->onQueue('high');
+ }
+
+ public function handle()
+ {
+ try {
+ instant_remote_process([
+ "docker volume create $this->targetVolume",
+ "docker run --rm -v $this->sourceVolume:/source -v $this->targetVolume:/target alpine sh -c 'cp -a /source/. /target/ && chown -R 1000:1000 /target'",
+ ], $this->server);
+ } catch (\Exception $e) {
+ logger()->error("Failed to copy volume data for {$this->sourceVolume}: ".$e->getMessage());
+ throw $e;
+ }
+ }
+}