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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
storages
Andras Bacsai96b9f8213cb9
diff --git a/app/Http/Livewire/Project/Application/EnvironmentVariable/Add.php b/app/Http/Livewire/Project/Application/EnvironmentVariable/Add.phpindex 3e1635a658..b182652d7b 100644--- a/app/Http/Livewire/Project/Application/EnvironmentVariable/Add.php+++ b/app/Http/Livewire/Project/Application/EnvironmentVariable/Add.php@@ -28,7 +28,6 @@ class Add extends Component{$this->validate();try {-$application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id;EnvironmentVariable::create(['key' => $this->key,diff --git a/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php b/app/Http/Livewire/Project/Application/EnvironmentVariable/All.phpindex 37c2bd7eca..05085b4331 100644--- a/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php+++ b/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php@@ -8,7 +8,7 @@ use Livewire\Component;class All extends Component{public Application $application;- protected $listeners = ['refreshEnvs' => 'refreshEnvs'];+ protected $listeners = ['refreshEnvs'];public function refreshEnvs(){$this->application->refresh();diff --git a/app/Http/Livewire/Project/Application/Storages.php b/app/Http/Livewire/Project/Application/Storages.phpdeleted file mode 100644index 38d5b45954..0000000000--- a/app/Http/Livewire/Project/Application/Storages.php+++ /dev/null@@ -1,11 +0,0 @@-<?php--namespace App\Http\Livewire\Project\Application;--use Illuminate\Database\Eloquent\Collection;-use Livewire\Component;--class Storages extends Component-{- public Collection $storages;-}diff --git a/app/Http/Livewire/Project/Application/Storages/Add.php b/app/Http/Livewire/Project/Application/Storages/Add.phpnew file mode 100644index 0000000000..4870638efe--- /dev/null+++ b/app/Http/Livewire/Project/Application/Storages/Add.php@@ -0,0 +1,52 @@+<?php++namespace App\Http\Livewire\Project\Application\Storages;++use App\Models\Application;+use App\Models\LocalPersistentVolume;+use Illuminate\Database\QueryException;+use Illuminate\Support\Facades\Route;+use Livewire\Component;++class Add extends Component+{+ public $parameters;+ public string $name;+ public string $mount_path;+ public string|null $host_path = null;+ protected $rules = [+ 'name' => 'required|string',+ 'mount_path' => 'required|string',+ 'host_path' => 'string|nullable',+ ];+ public function mount()+ {+ $this->parameters = Route::current()->parameters();+ }+ public function submit()+ {+ $this->validate();+ try {+ $application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id;+ LocalPersistentVolume::create([+ 'name' => $this->name,+ 'mount_path' => $this->mount_path,+ 'host_path' => $this->host_path,+ 'resource_id' => $application_id,+ 'resource_type' => Application::class,+ ]);+ $this->emit('refreshStorages');+ $this->name = '';+ $this->mount_path = '';+ $this->host_path = '';+ } catch (mixed $e) {+ dd('asdf');+ if ($e instanceof QueryException) {+ dd($e->errorInfo);+ $this->emit('error', $e->errorInfo[2]);+ } else {+ $this->emit('error', $e);+ }+ }+ }+}diff --git a/app/Http/Livewire/Project/Application/Storages/All.php b/app/Http/Livewire/Project/Application/Storages/All.phpnew file mode 100644index 0000000000..590350bdbc--- /dev/null+++ b/app/Http/Livewire/Project/Application/Storages/All.php@@ -0,0 +1,16 @@+<?php++namespace App\Http\Livewire\Project\Application\Storages;++use App\Models\Application;+use Livewire\Component;++class All extends Component+{+ public Application $application;+ protected $listeners = ['refreshStorages'];+ public function refreshStorages()+ {+ $this->application->refresh();+ }+}diff --git a/app/Http/Livewire/Project/Application/Storages/Show.php b/app/Http/Livewire/Project/Application/Storages/Show.phpnew file mode 100644index 0000000000..d9255f2845--- /dev/null+++ b/app/Http/Livewire/Project/Application/Storages/Show.php@@ -0,0 +1,25 @@+<?php++namespace App\Http\Livewire\Project\Application\Storages;++use Livewire\Component;++class Show extends Component+{+ public $storage;+ protected $rules = [+ 'storage.name' => 'required|string',+ 'storage.mount_path' => 'required|string',+ 'storage.host_path' => 'string|nullable',+ ];+ public function submit()+ {+ $this->validate();+ $this->storage->save();+ }+ public function delete()+ {+ $this->storage->delete();+ $this->emit('refreshStorages');+ }+}diff --git a/app/Models/LocalPersistentVolume.php b/app/Models/LocalPersistentVolume.phpindex e0cdfcc608..a8bb991f1a 100644--- a/app/Models/LocalPersistentVolume.php+++ b/app/Models/LocalPersistentVolume.php@@ -2,10 +2,45 @@namespace App\Models;+use Illuminate\Database\Eloquent\Casts\Attribute;+use Illuminate\Support\Str;+class LocalPersistentVolume extends BaseModel{+ protected $fillable = [+ 'name',+ 'mount_path',+ 'host_path',+ 'container_id',+ 'resource_id',+ 'resource_type',+ ];public function application(){return $this->morphTo();}+ protected function name(): Attribute+ {+ return Attribute::make(+ set: fn (string $value) => Str::of($value)->trim()->value,+ );+ }+ protected function mountPath(): Attribute+ {+ return Attribute::make(+ set: fn (string $value) => Str::of($value)->trim()->start('/')->value+ );+ }+ protected function hostPath(): Attribute+ {+ return Attribute::make(+ set: function (string|null $value) {+ if ($value) {+ return Str::of($value)->trim()->start('/')->value;+ } else {+ return $value;+ }+ }+ );+ }}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.phpindex d86178ec43..3f6d7aa8b6 100644--- 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@@ -14,12 +14,14 @@ return new class extends MigrationSchema::create('local_persistent_volumes', function (Blueprint $table) {$table->id();$table->string('uuid')->unique();- $table->string('name');+ $table->string('name')->unique();$table->string('mount_path');$table->string('host_path')->nullable();$table->string('container_id')->nullable();$table->nullableMorphs('resource');++ $table->unique(['name', 'resource_id', 'resource_type']);$table->timestamps();});}diff --git a/resources/views/components/inputs/button.blade.php b/resources/views/components/inputs/button.blade.phpindex 08f9f9d3ea..d74b199783 100644--- a/resources/views/components/inputs/button.blade.php+++ b/resources/views/components/inputs/button.blade.php@@ -1,8 +1,8 @@@props(['isWarning' => null,- 'defaultClass' => 'text-white bg-neutral-800 hover:bg-violet-600 w-28',- 'defaultWarningClass' => 'text-white bg-red-500 hover:bg-red-600 w-28',- 'loadingClass' => 'text-black bg-green-500 w-28',+ 'defaultClass' => 'text-white bg-neutral-800 hover:bg-violet-600 w-28 h-6',+ 'defaultWarningClass' => 'text-white bg-red-500 hover:bg-red-600 w-28 h-6',+ 'loadingClass' => 'text-black bg-green-500 w-28 h-6','confirm' => null,'confirmAction' => null,])diff --git a/resources/views/livewire/project/application/environment-variable/add.blade.php b/resources/views/livewire/project/application/environment-variable/add.blade.phpindex 4ad26a2f0e..03ba88a77d 100644--- a/resources/views/livewire/project/application/environment-variable/add.blade.php+++ b/resources/views/livewire/project/application/environment-variable/add.blade.php@@ -1,6 +1,6 @@-<form wire:submit.prevent='submit' class="flex gap-2 px-2">- <x-inputs.input noLabel noDirty id="key" required />- <x-inputs.input noLabel noDirty id="value" required />+<form wire:submit.prevent='submit' class="flex items-end gap-2 px-2">+ <x-inputs.input noDirty id="key" label="Name" required />+ <x-inputs.input noDirty id="value" label="Value" required /><div class="flex flex-col"><div class="flex items-center gap-2"><input type="checkbox" wire:model.defer="is_build_time" />diff --git a/resources/views/livewire/project/application/environment-variable/all.blade.php b/resources/views/livewire/project/application/environment-variable/all.blade.phpindex b68741be80..270efa283d 100644--- a/resources/views/livewire/project/application/environment-variable/all.blade.php+++ b/resources/views/livewire/project/application/environment-variable/all.blade.php@@ -1,7 +1,8 @@<div class="flex flex-col gap-2"><h3>Environment Variables</h3>@forelse ($application->environment_variables as $env)- <livewire:project.application.environment-variable.show wire:key="item-{{ $env->id }}" :env="$env" />+ <livewire:project.application.environment-variable.show wire:key="environment-{{ $env->id }}"+ :env="$env" />@empty<p>There are no environment variables for this application.</p>@endforelsediff --git a/resources/views/livewire/project/application/storages.blade.php b/resources/views/livewire/project/application/storages.blade.phpdeleted file mode 100644index 75d49bc785..0000000000--- a/resources/views/livewire/project/application/storages.blade.php+++ /dev/null@@ -1,10 +0,0 @@-<div>- @forelse ($storages as $storage)- <p>Name:{{ data_get($storage, 'name') }}</p>- <p>MountPath:{{ data_get($storage, 'mount_path') }}</p>- <p>HostPath:{{ data_get($storage, 'host_path') }}</p>- <p>ContainerId:{{ data_get($storage, 'container_id') }}</p>- @empty- <p>There are no storages added for this application.</p>- @endforelse-</div>diff --git a/resources/views/livewire/project/application/storages/add.blade.php b/resources/views/livewire/project/application/storages/add.blade.phpnew file mode 100644index 0000000000..e8cee8afdd--- /dev/null+++ b/resources/views/livewire/project/application/storages/add.blade.php@@ -0,0 +1,9 @@+<form wire:submit.prevent='submit' class="flex items-end gap-2 px-2">+ <x-inputs.input noDirty id="name" label="Name" required />+ <x-inputs.input noDirty id="mount_path" label="Mount Path (in your app)" required />+ <x-inputs.input noDirty id="host_path" label="Mount Path (host)" />++ <x-inputs.button type="submit">+ Add+ </x-inputs.button>+</form>diff --git a/resources/views/livewire/project/application/storages/all.blade.php b/resources/views/livewire/project/application/storages/all.blade.phpnew file mode 100644index 0000000000..31ec29bca8--- /dev/null+++ b/resources/views/livewire/project/application/storages/all.blade.php@@ -0,0 +1,10 @@+<div class="flex flex-col gap-2">+ <h3>Persistent Storages</h3>+ @forelse ($application->persistentStorages as $storage)+ <livewire:project.application.storages.show :storage="$storage" />+ @empty+ <p>There are no persistent storage attached for this application.</p>+ @endforelse+ <h4>Add new environment variable</h4>+ <livewire:project.application.storages.add />+</div>diff --git a/resources/views/livewire/project/application/storages/show.blade.php b/resources/views/livewire/project/application/storages/show.blade.phpnew file mode 100644index 0000000000..1f234e3305--- /dev/null+++ b/resources/views/livewire/project/application/storages/show.blade.php@@ -0,0 +1,15 @@+<div x-data="{ deleteStorage: false }">+ <form wire:submit.prevent='submit' class="flex items-end gap-2 px-2">+ <x-inputs.input id="storage.name" label="Name" required />+ <x-inputs.input id="storage.mount_path" label="Mount Path (in your app)" required />+ <x-inputs.input id="storage.host_path" label="Mount Path (host)" />++ <x-inputs.button type="submit">+ Update+ </x-inputs.button>+ <x-inputs.button x-on:click="deleteStorage = true" isWarning>+ Delete+ </x-inputs.button>+ </form>+ <x-naked-modal show="deleteStorage" message="Are you sure you want to delete {{ $storage->name }}?" />+</div>diff --git a/resources/views/project/application/configuration.blade.php b/resources/views/project/application/configuration.blade.phpindex 795268f1c5..c75e37f39e 100644--- a/resources/views/project/application/configuration.blade.php+++ b/resources/views/project/application/configuration.blade.php@@ -35,8 +35,7 @@<livewire:project.application.destination :destination="$application->destination" /></div><div x-cloak x-show="activeTab === 'storages'">- <h3>Persistent Storages</h3>- <livewire:project.application.storages :storages="$application->persistentStorages" />+ <livewire:project.application.storages.all :application="$application" /></div></div></x-layout>