wip: persisting data

This commit is contained in:
Andras Bacsai 2023-04-03 13:37:53 +02:00
parent 829a45f410
commit 259f41bb8a
10 changed files with 92 additions and 7 deletions

View File

@ -121,15 +121,25 @@ class DeployApplicationJob implements ShouldQueue
$this->execute_in_builder("cp {$this->workdir}/.nixpacks/Dockerfile {$this->workdir}/Dockerfile"), $this->execute_in_builder("cp {$this->workdir}/.nixpacks/Dockerfile {$this->workdir}/Dockerfile"),
$this->execute_in_builder("rm -f {$this->workdir}/.nixpacks/Dockerfile"), $this->execute_in_builder("rm -f {$this->workdir}/.nixpacks/Dockerfile"),
"echo 'Done.'", "echo 'Done.'",
]);
$this->executeNow([
"echo -n 'Building image... '", "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}"), $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.'", "echo 'Done.'",
]);
$this->executeNow([
"echo -n 'Removing old container... '",
$this->execute_in_builder("docker rm -f {$this->application->uuid} >/dev/null 2>&1"), $this->execute_in_builder("docker rm -f {$this->application->uuid} >/dev/null 2>&1"),
"echo -n 'Deploying... '", "echo 'Done.'",
$this->execute_in_builder("docker compose --project-directory {$this->workdir} up -d"), ]);
$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. 🎉'", "echo 'Done. 🎉'",
"docker stop -t 0 {$this->deployment_uuid} >/dev/null"
], setStatus: true); ], setStatus: true);
$this->executeNow([
"docker stop -t 0 {$this->deployment_uuid} >/dev/null"
]);
} }
private function execute_in_builder(string $command) private function execute_in_builder(string $command)

View File

@ -32,6 +32,10 @@ class Application extends BaseModel
{ {
return $this->morphTo(); return $this->morphTo();
} }
public function persistentStorages()
{
return $this->morphMany(LocalPersistentVolume::class, 'resource');
}
public function portsMappings(): Attribute public function portsMappings(): Attribute
{ {

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
class LocalPersistentVolume extends BaseModel
{
public function application()
{
return $this->morphTo();
}
}

View File

@ -17,8 +17,8 @@ return new class extends Migration
$table->string('name'); $table->string('name');
$table->morphs('destination'); $table->morphs('destination');
$table->foreignId('environment_id');
$table->foreignId('environment_id');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -17,6 +17,7 @@ return new class extends Migration
$table->string('name'); $table->string('name');
$table->morphs('destination'); $table->morphs('destination');
$table->foreignId('environment_id'); $table->foreignId('environment_id');
$table->timestamps(); $table->timestamps();
}); });

View File

@ -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');
}
};

View File

@ -6,6 +6,7 @@ use App\Models\Application;
use App\Models\ApplicationSetting; use App\Models\ApplicationSetting;
use App\Models\Environment; use App\Models\Environment;
use App\Models\GithubApp; use App\Models\GithubApp;
use App\Models\LocalPersistentVolume;
use App\Models\StandaloneDocker; use App\Models\StandaloneDocker;
use App\Models\SwarmDocker; use App\Models\SwarmDocker;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
@ -23,6 +24,8 @@ class ApplicationSeeder extends Seeder
$github_public_source = GithubApp::find(1); $github_public_source = GithubApp::find(1);
$github_private_source = GithubApp::find(2); $github_private_source = GithubApp::find(2);
$pv_storage = LocalPersistentVolume::find(1);
Application::create([ Application::create([
'id' => 1, 'id' => 1,
'name' => 'Public application (from GitHub)', 'name' => 'Public application (from GitHub)',

View File

@ -18,6 +18,7 @@ class DatabaseSeeder extends Seeder
ProjectSeeder::class, ProjectSeeder::class,
ProjectSettingSeeder::class, ProjectSettingSeeder::class,
EnvironmentSeeder::class, EnvironmentSeeder::class,
LocalPersistentVolumeSeeder::class,
StandaloneDockerSeeder::class, StandaloneDockerSeeder::class,
SwarmDockerSeeder::class, SwarmDockerSeeder::class,
KubernetesSeeder::class, KubernetesSeeder::class,

View File

@ -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,
]);
}
}

View File

@ -1,5 +1,3 @@
<div> <div>
<pre style="width: 100%;overflow-y: scroll;" @if ($isKeepAliveOn) wire:poll.750ms="polling" @endif> <pre style="width: 100%;overflow-y: scroll;" @if ($isKeepAliveOn) wire:poll.750ms="polling" @endif>{{ data_get($activity, 'description') }}</pre>
{{ data_get($activity, 'description') }}
</pre>
</div> </div>