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 @@ public function handle(): void
$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)

View File

@ -32,6 +32,10 @@ public function source()
{
return $this->morphTo();
}
public function persistentStorages()
{
return $this->morphMany(LocalPersistentVolume::class, 'resource');
}
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 @@ public function up(): void
$table->string('name');
$table->morphs('destination');
$table->foreignId('environment_id');
$table->foreignId('environment_id');
$table->timestamps();
});
}

View File

@ -17,6 +17,7 @@ public function up(): void
$table->string('name');
$table->morphs('destination');
$table->foreignId('environment_id');
$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\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 @@ public function run(): void
$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)',

View File

@ -18,6 +18,7 @@ public function run(): void
ProjectSeeder::class,
ProjectSettingSeeder::class,
EnvironmentSeeder::class,
LocalPersistentVolumeSeeder::class,
StandaloneDockerSeeder::class,
SwarmDockerSeeder::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>
<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>