From 0fbc382467f319e67a0fc86bee4b572c5fe9abfd Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 25 Sep 2023 17:51:04 +0200 Subject: [PATCH] feat: image tag for services --- app/Http/Livewire/Project/Service/Application.php | 1 + app/Http/Livewire/Project/Service/Database.php | 2 +- app/Models/Service.php | 7 +++++++ ...9_23_111811_update_service_applications_table.php | 2 ++ ...3_09_23_111812_update_service_databases_table.php | 3 ++- .../livewire/project/service/application.blade.php | 6 +++++- .../livewire/project/service/database.blade.php | 12 +++++++++--- 7 files changed, 27 insertions(+), 6 deletions(-) diff --git a/app/Http/Livewire/Project/Service/Application.php b/app/Http/Livewire/Project/Service/Application.php index 9bebb84e8..44538278e 100644 --- a/app/Http/Livewire/Project/Service/Application.php +++ b/app/Http/Livewire/Project/Service/Application.php @@ -15,6 +15,7 @@ class Application extends Component 'application.human_name' => 'nullable', 'application.description' => 'nullable', 'application.fqdn' => 'nullable', + 'application.image_tag' => 'required', 'application.ignore_from_status' => 'required|boolean', ]; public function render() diff --git a/app/Http/Livewire/Project/Service/Database.php b/app/Http/Livewire/Project/Service/Database.php index 1a6ce772a..36dd96d36 100644 --- a/app/Http/Livewire/Project/Service/Database.php +++ b/app/Http/Livewire/Project/Service/Database.php @@ -2,7 +2,6 @@ namespace App\Http\Livewire\Project\Service; -use App\Models\ServiceApplication; use App\Models\ServiceDatabase; use Livewire\Component; @@ -12,6 +11,7 @@ class Database extends Component protected $rules = [ 'database.human_name' => 'nullable', 'database.description' => 'nullable', + 'database.image_tag' => 'required', 'database.ignore_from_status' => 'required|boolean', ]; diff --git a/app/Models/Service.php b/app/Models/Service.php index 864251260..f6c12ccff 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -139,6 +139,7 @@ public function parse(bool $isNew = false): Collection $image = data_get($service, 'image'); if ($image) { $imageName = Str::of($image)->before(':'); + $imageTag = Str::of($image)->after(':') ?? 'latest'; if (collect(DATABASE_DOCKER_IMAGES)->contains($imageName)) { $isDatabase = true; data_set($service, 'is_database', true); @@ -159,12 +160,14 @@ public function parse(bool $isNew = false): Collection if ($isDatabase) { $savedService = ServiceDatabase::create([ 'name' => $serviceName, + 'image_tag' => $imageTag, 'service_id' => $this->id ]); } else { $savedService = ServiceApplication::create([ 'name' => $serviceName, 'fqdn' => $this->generateFqdn($serviceVariables, $serviceName), + 'image_tag' => $imageTag, 'service_id' => $this->id ]); } @@ -182,6 +185,8 @@ public function parse(bool $isNew = false): Collection $savedService->save(); } } + + // Set image tag $fqdns = data_get($savedService, 'fqdn'); if ($fqdns) { $fqdns = collect(Str::of($fqdns)->explode(',')); @@ -495,6 +500,8 @@ public function parse(bool $isNew = false): Collection $labels = $labels->merge(fqdnLabelsForTraefik($fqdns, $container_name, true)); } } + + data_set($service, 'labels', $labels->toArray()); data_forget($service, 'is_database'); data_set($service, 'restart', RESTART_MODE); diff --git a/database/migrations/2023_09_23_111811_update_service_applications_table.php b/database/migrations/2023_09_23_111811_update_service_applications_table.php index 9d241aec2..68ddab8d5 100644 --- a/database/migrations/2023_09_23_111811_update_service_applications_table.php +++ b/database/migrations/2023_09_23_111811_update_service_applications_table.php @@ -13,6 +13,7 @@ public function up(): void { Schema::table('service_applications', function (Blueprint $table) { $table->boolean('ignore_from_status')->default(false); + $table->string('image_tag')->nullable(); }); } @@ -23,6 +24,7 @@ public function down(): void { Schema::table('service_applications', function (Blueprint $table) { $table->dropColumn('ignore_from_status'); + $table->dropColumn('image_tag'); }); } }; diff --git a/database/migrations/2023_09_23_111812_update_service_databases_table.php b/database/migrations/2023_09_23_111812_update_service_databases_table.php index 659cbd2a3..bcf42abfd 100644 --- a/database/migrations/2023_09_23_111812_update_service_databases_table.php +++ b/database/migrations/2023_09_23_111812_update_service_databases_table.php @@ -13,7 +13,7 @@ public function up(): void { Schema::table('service_databases', function (Blueprint $table) { $table->boolean('ignore_from_status')->default(false); - + $table->string('image_tag')->nullable(); }); } @@ -24,6 +24,7 @@ public function down(): void { Schema::table('service_databases', function (Blueprint $table) { $table->dropColumn('ignore_from_status'); + $table->dropColumn('image_tag'); }); } }; diff --git a/resources/views/livewire/project/service/application.blade.php b/resources/views/livewire/project/service/application.blade.php index 282995acb..69f47fc5d 100644 --- a/resources/views/livewire/project/service/application.blade.php +++ b/resources/views/livewire/project/service/application.blade.php @@ -16,7 +16,11 @@ placeholder="Human readable name"> - +
+ + +

Advanced

diff --git a/resources/views/livewire/project/service/database.blade.php b/resources/views/livewire/project/service/database.blade.php index 36f937859..596ef3ec7 100644 --- a/resources/views/livewire/project/service/database.blade.php +++ b/resources/views/livewire/project/service/database.blade.php @@ -9,9 +9,15 @@ Save Documentation
-
- - +
+
+ + +
+
+ +

Advanced