diff --git a/app/Http/Livewire/Project/Service/Application.php b/app/Http/Livewire/Project/Service/Application.php index bac6c6505..77b0c89af 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 ]; public function render() { + ray($this->application->fileStorages()->get()); return view('livewire.project.service.application'); } public function submit() diff --git a/app/Http/Livewire/Project/Service/FileStorage.php b/app/Http/Livewire/Project/Service/FileStorage.php new file mode 100644 index 000000000..7ad98bc45 --- /dev/null +++ b/app/Http/Livewire/Project/Service/FileStorage.php @@ -0,0 +1,21 @@ + 'required', + 'fileStorage.mount_path' => 'required', + 'fileStorage.content' => 'nullable', + ]; + public function render() + { + return view('livewire.project.service.file-storage'); + } +} diff --git a/app/Models/LocalFileVolume.php b/app/Models/LocalFileVolume.php new file mode 100644 index 000000000..b771decf6 --- /dev/null +++ b/app/Models/LocalFileVolume.php @@ -0,0 +1,16 @@ +morphTo(); + } +} diff --git a/app/Models/Service.php b/app/Models/Service.php index afc916359..4b66fdf19 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Collection; use Symfony\Component\Yaml\Yaml; use Illuminate\Support\Str; +use Spatie\Url\Url; class Service extends BaseModel { @@ -84,7 +85,11 @@ class Service extends BaseModel ray('parsing'); // ray()->clearAll(); if ($this->docker_compose_raw) { - $yaml = Yaml::parse($this->docker_compose_raw); + try { + $yaml = Yaml::parse($this->docker_compose_raw); + } catch (\Exception $e) { + throw new \Exception($e->getMessage()); + } $composeVolumes = collect(data_get($yaml, 'volumes', [])); $composeNetworks = collect(data_get($yaml, 'networks', [])); @@ -173,6 +178,26 @@ class Service extends BaseModel if ($serviceVolumes->count() > 0) { LocalPersistentVolume::whereResourceId($savedService->id)->whereResourceType(get_class($savedService))->delete(); foreach ($serviceVolumes as $volume) { + if (is_string($volume) && Str::startsWith($volume, './')) { + // Local file + $fsPath = Str::before($volume, ':'); + $volumePath = Str::of($volume)->after(':')->beforeLast(':'); + ray($fsPath, $volumePath); + LocalFileVolume::updateOrCreate( + [ + 'mount_path' => $volumePath, + 'resource_id' => $savedService->id, + 'resource_type' => get_class($savedService) + ], + [ + 'fs_path' => $fsPath, + 'mount_path' => $volumePath, + 'resource_id' => $savedService->id, + 'resource_type' => get_class($savedService) + ] + ); + continue; + } if (is_string($volume)) { $volumeName = Str::before($volume, ':'); $volumePath = Str::after($volume, ':'); @@ -352,7 +377,7 @@ class Service extends BaseModel } else { $number = 0; } - $fqdn = data_get($fqdns, $number); + $fqdn = getOnlyFqdn(data_get($fqdns, $number, $fqdns->first())); $environments = collect(data_get($service, 'environment')); $environments = $environments->map(function ($envValue) use ($value, $fqdn) { $envValue = Str::of($envValue)->replace($value, $fqdn); @@ -361,9 +386,15 @@ class Service extends BaseModel $service['environment'] = $environments->toArray(); } } else if ($variableName->startsWith('SERVICE_URL')) { - ray('url'); if ($fqdns) { - $url = Str::of($fqdns)->after('https://')->before('/'); + $number = Str::of($variableName)->after('SERVICE_URL')->afterLast('_')->value(); + if (is_numeric($number)) { + $number = (int) $number - 1; + } else { + $number = 0; + } + $fqdn = getOnlyFqdn(data_get($fqdns, $number, $fqdns->first())); + $url = Url::fromString($fqdn)->getHost(); $environments = collect(data_get($service, 'environment')); $environments = $environments->map(function ($envValue) use ($value, $url) { $envValue = Str::of($envValue)->replace($value, $url); diff --git a/app/Models/ServiceApplication.php b/app/Models/ServiceApplication.php index 491058082..3e21649db 100644 --- a/app/Models/ServiceApplication.php +++ b/app/Models/ServiceApplication.php @@ -27,4 +27,8 @@ class ServiceApplication extends BaseModel { return $this->morphMany(LocalPersistentVolume::class, 'resource'); } + public function fileStorages() + { + return $this->morphMany(LocalFileVolume::class, 'resource'); + } } diff --git a/database/migrations/2023_09_22_185356_create_local_file_volumes_table.php b/database/migrations/2023_09_22_185356_create_local_file_volumes_table.php new file mode 100644 index 000000000..9dc6e13bb --- /dev/null +++ b/database/migrations/2023_09_22_185356_create_local_file_volumes_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('uuid'); + $table->mediumText('fs_path'); + $table->string('mount_path'); + $table->mediumText('content')->nullable(); + $table->nullableMorphs('resource'); + + $table->unique(['mount_path', 'resource_id', 'resource_type']); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('local_file_volumes'); + } +}; diff --git a/database/seeders/LocalFileVolumeSeeder.php b/database/seeders/LocalFileVolumeSeeder.php new file mode 100644 index 000000000..68a425dbf --- /dev/null +++ b/database/seeders/LocalFileVolumeSeeder.php @@ -0,0 +1,17 @@ + -