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.

wip: persisting data

Andras Bacsai259f41bb8a12
diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php
index ce8dd7bd99..2e1ee1aac8 100644
--- a/app/Jobs/DeployApplicationJob.php
+++ b/app/Jobs/DeployApplicationJob.php
@@ -121,15 +121,25 @@ class DeployApplicationJob implements ShouldQueue
$this->execute_in_builder("cp {$this->workdir}/.nixpacks/Dockerfile {$this->workdir}/Dockerfile"),
$this->execute_in_builder("rm -f {$this->workdir}/.nixpacks/Dockerfile"),
"echo 'Done.'",
+ ]);
+ $this->executeNow([
"echo -n 'Building image... '",
$this->execute_in_builder("docker build -f {$this->workdir}/Dockerfile --build-arg SOURCE_COMMIT={$this->git_commit} --progress plain -t {$this->application->uuid}:{$this->git_commit} {$this->workdir}"),
"echo 'Done.'",
+ ]);
+ $this->executeNow([
+ "echo -n 'Removing old container... '",
$this->execute_in_builder("docker rm -f {$this->application->uuid} >/dev/null 2>&1"),
- "echo -n 'Deploying... '",
- $this->execute_in_builder("docker compose --project-directory {$this->workdir} up -d"),
+ "echo 'Done.'",
+ ]);
+ $this->executeNow([
+ "echo -n 'Starting new container... '",
+ $this->execute_in_builder("docker compose --project-directory {$this->workdir} up -d >/dev/null 2>&1"),
"echo 'Done. 🎉'",
- "docker stop -t 0 {$this->deployment_uuid} >/dev/null"
], setStatus: true);
+ $this->executeNow([
+ "docker stop -t 0 {$this->deployment_uuid} >/dev/null"
+ ]);
}
private function execute_in_builder(string $command)
diff --git a/app/Models/Application.php b/app/Models/Application.php
index a139bc6a8e..69272808be 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -32,6 +32,10 @@ class Application extends BaseModel
{
return $this->morphTo();
}
+ public function persistentStorages()
+ {
+ return $this->morphMany(LocalPersistentVolume::class, 'resource');
+ }
public function portsMappings(): Attribute
{
diff --git a/app/Models/LocalPersistentVolume.php b/app/Models/LocalPersistentVolume.php
new file mode 100644
index 0000000000..e0cdfcc608
--- /dev/null
+++ b/app/Models/LocalPersistentVolume.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+class LocalPersistentVolume extends BaseModel
+{
+ public function application()
+ {
+ return $this->morphTo();
+ }
+}
diff --git a/database/migrations/2023_03_27_083620_create_databases_table.php b/database/migrations/2023_03_27_083620_create_databases_table.php
index 9173e4b117..bfafb9c0c6 100644
--- a/database/migrations/2023_03_27_083620_create_databases_table.php
+++ b/database/migrations/2023_03_27_083620_create_databases_table.php
@@ -17,8 +17,8 @@ return new class extends Migration
$table->string('name');
$table->morphs('destination');
- $table->foreignId('environment_id');
+ $table->foreignId('environment_id');
$table->timestamps();
});
}
diff --git a/database/migrations/2023_03_27_083621_create_services_table.php b/database/migrations/2023_03_27_083621_create_services_table.php
index a5c10c0b02..12bb77b1ba 100644
--- a/database/migrations/2023_03_27_083621_create_services_table.php
+++ b/database/migrations/2023_03_27_083621_create_services_table.php
@@ -17,6 +17,7 @@ return new class extends Migration
$table->string('name');
$table->morphs('destination');
+
$table->foreignId('environment_id');
$table->timestamps();
});
diff --git a/database/migrations/2023_04_03_111012_create_local_persistent_volumes_table.php b/database/migrations/2023_04_03_111012_create_local_persistent_volumes_table.php
new file mode 100644
index 0000000000..d86178ec43
--- /dev/null
+++ b/database/migrations/2023_04_03_111012_create_local_persistent_volumes_table.php
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ Schema::create('local_persistent_volumes', function (Blueprint $table) {
+ $table->id();
+ $table->string('uuid')->unique();
+ $table->string('name');
+ $table->string('mount_path');
+ $table->string('host_path')->nullable();
+ $table->string('container_id')->nullable();
+
+ $table->nullableMorphs('resource');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('local_persistent_volumes');
+ }
+};
diff --git a/database/seeders/ApplicationSeeder.php b/database/seeders/ApplicationSeeder.php
index 3a8fcde681..c3c6b16aeb 100644
--- a/database/seeders/ApplicationSeeder.php
+++ b/database/seeders/ApplicationSeeder.php
@@ -6,6 +6,7 @@ use App\Models\Application;
use App\Models\ApplicationSetting;
use App\Models\Environment;
use App\Models\GithubApp;
+use App\Models\LocalPersistentVolume;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Illuminate\Database\Seeder;
@@ -23,6 +24,8 @@ class ApplicationSeeder extends Seeder
$github_public_source = GithubApp::find(1);
$github_private_source = GithubApp::find(2);
+
+ $pv_storage = LocalPersistentVolume::find(1);
Application::create([
'id' => 1,
'name' => 'Public application (from GitHub)',
diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php
index 76395f2b0b..8588b5082e 100644
--- a/database/seeders/DatabaseSeeder.php
+++ b/database/seeders/DatabaseSeeder.php
@@ -18,6 +18,7 @@ class DatabaseSeeder extends Seeder
ProjectSeeder::class,
ProjectSettingSeeder::class,
EnvironmentSeeder::class,
+ LocalPersistentVolumeSeeder::class,
StandaloneDockerSeeder::class,
SwarmDockerSeeder::class,
KubernetesSeeder::class,
diff --git a/database/seeders/LocalPersistentVolumeSeeder.php b/database/seeders/LocalPersistentVolumeSeeder.php
new file mode 100644
index 0000000000..79c105ed36
--- /dev/null
+++ b/database/seeders/LocalPersistentVolumeSeeder.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Database\Seeders;
+
+use App\Models\Application;
+use App\Models\LocalPersistentVolume;
+use Illuminate\Database\Seeder;
+
+class LocalPersistentVolumeSeeder extends Seeder
+{
+ /**
+ * Run the database seeds.
+ */
+ public function run(): void
+ {
+ LocalPersistentVolume::create([
+ 'name' => 'test-pv',
+ 'mount_path' => '/data',
+ 'resource_id' => 1,
+ 'resource_type' => Application::class,
+ ]);
+ }
+}
diff --git a/resources/views/livewire/poll-activity.blade.php b/resources/views/livewire/poll-activity.blade.php
index bc939f7d46..4a91ba6228 100644
--- a/resources/views/livewire/poll-activity.blade.php
+++ b/resources/views/livewire/poll-activity.blade.php
@@ -1,5 +1,3 @@
<div>
- <pre style="width: 100%;overflow-y: scroll;" @if ($isKeepAliveOn) wire:poll.750ms="polling" @endif>
- {{ data_get($activity, 'description') }}
- </pre>
+ <pre style="width: 100%;overflow-y: scroll;" @if ($isKeepAliveOn) wire:poll.750ms="polling" @endif>{{ data_get($activity, 'description') }}</pre>
</div>