diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index ce8dd7bd9..2e1ee1aac 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 a139bc6a8..69272808b 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 000000000..e0cdfcc60 --- /dev/null +++ b/app/Models/LocalPersistentVolume.php @@ -0,0 +1,11 @@ +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 9173e4b11..bfafb9c0c 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 a5c10c0b0..12bb77b1b 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 000000000..d86178ec4 --- /dev/null +++ b/database/migrations/2023_04_03_111012_create_local_persistent_volumes_table.php @@ -0,0 +1,34 @@ +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 3a8fcde68..c3c6b16ae 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 76395f2b0..8588b5082 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 000000000..79c105ed3 --- /dev/null +++ b/database/seeders/LocalPersistentVolumeSeeder.php @@ -0,0 +1,23 @@ + '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 bc939f7d4..4a91ba622 100644 --- a/resources/views/livewire/poll-activity.blade.php +++ b/resources/views/livewire/poll-activity.blade.php @@ -1,5 +1,3 @@
- {{ data_get($activity, 'description') }} -+
{{ data_get($activity, 'description') }}