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.

fix: create S3 event classes and add formatBytes helper

Andras Bacsai3fc626c6da79
diff --git a/app/Events/S3DownloadFinished.php b/app/Events/S3DownloadFinished.php
new file mode 100644
index 0000000000..4ca11fdd06
--- /dev/null
+++ b/app/Events/S3DownloadFinished.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Events;
+
+use App\Models\Server;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class S3DownloadFinished
+{
+ use Dispatchable, InteractsWithSockets, SerializesModels;
+
+ public function __construct($data)
+ {
+ $containerName = data_get($data, 'containerName');
+ $serverId = data_get($data, 'serverId');
+
+ if (filled($containerName) && filled($serverId)) {
+ // Clean up the MinIO client container
+ $commands = [];
+ $commands[] = "docker stop {$containerName} 2>/dev/null || true";
+ $commands[] = "docker rm {$containerName} 2>/dev/null || true";
+ instant_remote_process($commands, Server::find($serverId), throwError: false);
+ }
+ }
+}
diff --git a/app/Events/S3RestoreJobFinished.php b/app/Events/S3RestoreJobFinished.php
new file mode 100644
index 0000000000..924bc94b19
--- /dev/null
+++ b/app/Events/S3RestoreJobFinished.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace App\Events;
+
+use App\Models\Server;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+class S3RestoreJobFinished
+{
+ use Dispatchable, InteractsWithSockets, SerializesModels;
+
+ public function __construct($data)
+ {
+ $scriptPath = data_get($data, 'scriptPath');
+ $tmpPath = data_get($data, 'tmpPath');
+ $container = data_get($data, 'container');
+ $serverId = data_get($data, 'serverId');
+ $s3DownloadedFile = data_get($data, 's3DownloadedFile');
+
+ // Clean up temporary files from container
+ if (filled($scriptPath) && filled($tmpPath) && filled($container) && filled($serverId)) {
+ if (str($tmpPath)->startsWith('/tmp/')
+ && str($scriptPath)->startsWith('/tmp/')
+ && ! str($tmpPath)->contains('..')
+ && ! str($scriptPath)->contains('..')
+ && strlen($tmpPath) > 5 // longer than just "/tmp/"
+ && strlen($scriptPath) > 5
+ ) {
+ $commands[] = "docker exec {$container} sh -c 'rm {$scriptPath}'";
+ $commands[] = "docker exec {$container} sh -c 'rm {$tmpPath}'";
+ instant_remote_process($commands, Server::find($serverId), throwError: true);
+ }
+ }
+
+ // Clean up S3 downloaded file from server
+ if (filled($s3DownloadedFile) && filled($serverId)) {
+ if (str($s3DownloadedFile)->startsWith('/tmp/s3-restore-')
+ && ! str($s3DownloadedFile)->contains('..')
+ && strlen($s3DownloadedFile) > 16 // longer than just "/tmp/s3-restore-"
+ ) {
+ $commands = [];
+ $commands[] = "rm -f {$s3DownloadedFile}";
+ instant_remote_process($commands, Server::find($serverId), throwError: false);
+ }
+ }
+ }
+}
diff --git a/app/Livewire/Project/Database/Import.php b/app/Livewire/Project/Database/Import.php
index c2490bee6f..95597e8eac 100644
--- a/app/Livewire/Project/Database/Import.php
+++ b/app/Livewire/Project/Database/Import.php
@@ -74,17 +74,9 @@ class Import extends Component
return [
"echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh',
- 'S3DownloadFinished' => 'handleS3DownloadFinished',
];
}
- public function handleS3DownloadFinished(): void
- {
- ray('S3DownloadFinished event received!');
- $this->s3DownloadInProgress = false;
- ray('s3DownloadInProgress set to false', $this->s3DownloadInProgress);
- }
-
public function mount()
{
if (isDev()) {
@@ -402,7 +394,7 @@ EOD;
$commands[] = "docker exec {$containerName} mc cp temporary/{$bucket}/{$cleanPath} {$downloadPath}";
// Execute download commands
- $activity = remote_process($commands, $this->server, ignore_errors: false, callEventOnFinish: 'S3DownloadFinished', callEventData: [
+ $activity = remote_process($commands, $this->server, ignore_errors: false, callEventOnFinish: 'App\\Events\\S3DownloadFinished', callEventData: [
'downloadPath' => $downloadPath,
'containerName' => $containerName,
'serverId' => $this->server->id,
@@ -486,7 +478,7 @@ EOD;
$this->importCommands[] = "docker exec {$this->container} sh -c 'echo \"Import finished with exit code $?\"'";
if (! empty($this->importCommands)) {
- $activity = remote_process($this->importCommands, $this->server, ignore_errors: true, callEventOnFinish: 'S3RestoreJobFinished', callEventData: [
+ $activity = remote_process($this->importCommands, $this->server, ignore_errors: true, callEventOnFinish: 'App\\Events\\S3RestoreJobFinished', callEventData: [
'scriptPath' => $scriptPath,
'tmpPath' => $tmpPath,
'container' => $this->container,