Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

wip: services

Andras Bacsai175244805034
diff --git a/app/Http/Livewire/Project/Service/Application.php b/app/Http/Livewire/Project/Service/Application.php
index bac6c65051..77b0c89af2 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 0000000000..7ad98bc45f
--- /dev/null
+++ b/app/Http/Livewire/Project/Service/FileStorage.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Http\Livewire\Project\Service;
+
+use App\Models\LocalFileVolume;
+use Livewire\Component;
+
+class FileStorage extends Component
+{
+ public LocalFileVolume $fileStorage;
+
+ protected $rules = [
+ 'fileStorage.fs_path' => '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 0000000000..b771decf64
--- /dev/null
+++ b/app/Models/LocalFileVolume.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+
+class LocalFileVolume extends BaseModel
+{
+ use HasFactory;
+ protected $guarded = [];
+
+ public function service()
+ {
+ return $this->morphTo();
+ }
+}
diff --git a/app/Models/Service.php b/app/Models/Service.php
index afc9163597..4b66fdf190 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 4910580821..3e21649dbd 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 0000000000..9dc6e13bb0
--- /dev/null
+++ b/database/migrations/2023_09_22_185356_create_local_file_volumes_table.php
@@ -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_file_volumes', function (Blueprint $table) {
+ $table->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 0000000000..68a425dbf3
--- /dev/null
+++ b/database/seeders/LocalFileVolumeSeeder.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace Database\Seeders;
+
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
+use Illuminate\Database\Seeder;
+
+class LocalFileVolumeSeeder extends Seeder
+{
+ /**
+ * Run the database seeds.
+ */
+ public function run(): void
+ {
+ //
+ }
+}
diff --git a/resources/views/livewire/project/service/application.blade.php b/resources/views/livewire/project/service/application.blade.php
index 323e877d20..5c2636d8cc 100644
--- a/resources/views/livewire/project/service/application.blade.php
+++ b/resources/views/livewire/project/service/application.blade.php
@@ -1,17 +1,27 @@
-<form wire:submit.prevent='submit'>
- <div class="flex items-center gap-2 pb-4">
- @if ($application->human_name)
- <h2>{{ Str::headline($application->human_name) }}</h2>
- @else
- <h2>{{ Str::headline($application->name) }}</h2>
- @endif
- <x-forms.button type="submit">Save</x-forms.button>
- <a target="_blank" href="{{ $application->documentation() }}">Documentation <x-external-link /></a>
- </div>
- <div class="flex gap-2">
- <x-forms.input label="Name" id="application.human_name" placeholder="Human readable name"></x-forms.input>
- <x-forms.input label="Description" id="application.description"></x-forms.input>
- <x-forms.input placeholder="https://app.coolify.io" label="Domains" required
- id="application.fqdn"></x-forms.input>
- </div>
-</form>
+<div>
+ <form wire:submit.prevent='submit'>
+ <div class="flex items-center gap-2 pb-4">
+ @if ($application->human_name)
+ <h2>{{ Str::headline($application->human_name) }}</h2>
+ @else
+ <h2>{{ Str::headline($application->name) }}</h2>
+ @endif
+ <x-forms.button type="submit">Save</x-forms.button>
+ <a target="_blank" href="{{ $application->documentation() }}">Documentation <x-external-link /></a>
+ </div>
+ <div class="flex gap-2">
+ <x-forms.input label="Name" id="application.human_name" placeholder="Human readable name"></x-forms.input>
+ <x-forms.input label="Description" id="application.description"></x-forms.input>
+ <x-forms.input placeholder="https://app.coolify.io" label="Domains" required
+ id="application.fqdn"></x-forms.input>
+ </div>
+ </form>
+ @if ($application->fileStorages()->get()->count() > 0)
+ <h3 class="py-4">File Storages</h3>
+ <div class="flex flex-col gap-4">
+ @foreach ($application->fileStorages()->get() as $fileStorage)
+ <livewire:project.service.file-storage :fileStorage="$fileStorage" wire:key="{{ $loop->index }}" />
+ @endforeach
+ </div>
+ @endif
+</div>
diff --git a/resources/views/livewire/project/service/file-storage.blade.php b/resources/views/livewire/project/service/file-storage.blade.php
new file mode 100644
index 0000000000..c3092ccdbc
--- /dev/null
+++ b/resources/views/livewire/project/service/file-storage.blade.php
@@ -0,0 +1,8 @@
+<form wire:submit.prevent='submit' class="flex flex-col gap-2">
+ <div class="flex gap-2">
+ <x-forms.input readonly label="File Path" id="fileStorage.fs_path"></x-forms.input>
+ <x-forms.input readonly label="Mount Path (in container)" id="fileStorage.mount_path"></x-forms.input>
+ </div>
+ <x-forms.textarea label="Content" id="fileStorage.content"></x-forms.textarea>
+ <x-forms.button type="submit">Save</x-forms.button>
+</form>