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
wip: ui for services
Andras Bacsai53d1fa033143
diff --git a/app/Actions/Service/StartService.php b/app/Actions/Service/StartService.phpindex c89759bf79..1dbabc6a57 100644--- a/app/Actions/Service/StartService.php+++ b/app/Actions/Service/StartService.php@@ -18,6 +18,7 @@ class StartService$docker_compose_base64 = base64_encode($service->docker_compose);$commands[] = "echo $docker_compose_base64 | base64 -d > docker-compose.yml";$envs = $service->environment_variables()->get();+ $commands[] = "rm -f .env || true";foreach ($envs as $env) {$commands[] = "echo '{$env->key}={$env->value}' >> .env";}diff --git a/app/Http/Livewire/Project/Service/Application.php b/app/Http/Livewire/Project/Service/Application.phpnew file mode 100644index 0000000000..0177de30c7--- /dev/null+++ b/app/Http/Livewire/Project/Service/Application.php@@ -0,0 +1,30 @@+<?php++namespace App\Http\Livewire\Project\Service;++use App\Models\ServiceApplication;+use Livewire\Component;++class Application extends Component+{+ public ServiceApplication $application;+ protected $rules = [+ 'application.human_name' => 'nullable',+ 'application.fqdn' => 'nullable',+ ];+ public function render()+ {+ return view('livewire.project.service.application');+ }+ public function submit()+ {+ try {+ $this->validate();+ $this->application->save();+ } catch (\Throwable $e) {+ ray($e);+ } finally {+ $this->emit('generateDockerCompose');+ }+ }+}diff --git a/app/Http/Livewire/Project/Service/Database.php b/app/Http/Livewire/Project/Service/Database.phpnew file mode 100644index 0000000000..709eb2c350--- /dev/null+++ b/app/Http/Livewire/Project/Service/Database.php@@ -0,0 +1,30 @@+<?php++namespace App\Http\Livewire\Project\Service;++use App\Models\ServiceApplication;+use App\Models\ServiceDatabase;+use Livewire\Component;++class Database extends Component+{+ public ServiceDatabase $database;+ protected $rules = [+ 'database.human_name' => 'nullable',+ ];+ public function render()+ {+ return view('livewire.project.service.database');+ }+ public function submit()+ {+ try {+ $this->validate();+ $this->database->save();+ } catch (\Throwable $e) {+ ray($e);+ } finally {+ $this->emit('generateDockerCompose');+ }+ }+}diff --git a/app/Http/Livewire/Project/Service/Index.php b/app/Http/Livewire/Project/Service/Index.phpindex 09a0c059fc..8b70f369f8 100644--- a/app/Http/Livewire/Project/Service/Index.php+++ b/app/Http/Livewire/Project/Service/Index.php@@ -15,73 +15,25 @@ class Index extends Componentpublic array $parameters;public array $query;- public Collection $services;- protected $listeners = ['serviceStatusUpdated'];protected $rules = [- 'services.*.fqdn' => 'nullable',+ 'service.docker_compose_raw' => 'required',+ 'service.docker_compose' => 'required',];public function mount(){- $this->services = collect([]);$this->parameters = get_route_parameters();$this->query = request()->query();$this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();- foreach ($this->service->applications as $application) {- $this->services->put($application->name, [- 'fqdn' => $application->fqdn,- ]);- }- // foreach ($this->service->databases as $database) {- // $this->services->put($database->name, $database->fqdn);- // }}public function render(){- return view('livewire.project.service.index')->layout('layouts.app');+ return view('livewire.project.service.index');}- public function serviceStatusUpdated() {- ray('serviceStatusUpdated');- $this->check_status();- }- public function check_status()- {- dispatch_sync(new ContainerStatusJob($this->service->server));- $this->service->refresh();- }- public function submit()- {- try {- if ($this->services->count() === 0) {- return;- }- foreach ($this->services as $name => $value) {- $foundService = $this->service->applications()->whereName($name)->first();- if ($foundService) {- $foundService->fqdn = data_get($value, 'fqdn');- $foundService->save();- return;- }- $foundService = $this->service->databases()->whereName($name)->first();- if ($foundService) {- // $foundService->save();- return;- }- }- } catch (\Throwable $e) {- ray($e);- } finally {- $this->service->parse();- }- }- public function deploy()- {+ public function save() {+ $this->service->save();$this->service->parse();- $activity = StartService::run($this->service);- $this->emit('newMonitorActivity', $activity->id);- }- public function stop() {- StopService::run($this->service);- $this->service->refresh();+ $this->emit('refreshEnvs');}+}diff --git a/app/Http/Livewire/Project/Service/Navbar.php b/app/Http/Livewire/Project/Service/Navbar.phpnew file mode 100644index 0000000000..b7f2730b6c--- /dev/null+++ b/app/Http/Livewire/Project/Service/Navbar.php@@ -0,0 +1,43 @@+<?php++namespace App\Http\Livewire\Project\Service;++use App\Actions\Service\StartService;+use App\Actions\Service\StopService;+use App\Jobs\ContainerStatusJob;+use App\Models\Service;+use Livewire\Component;++class Navbar extends Component+{+ public Service $service;+ public array $parameters;+ public array $query;+ protected $listeners = ['serviceStatusUpdated'];++ public function render()+ {+ return view('livewire.project.service.navbar');+ }+ public function serviceStatusUpdated()+ {+ ray('serviceStatusUpdated');+ $this->check_status();+ }+ public function check_status()+ {+ dispatch_sync(new ContainerStatusJob($this->service->server));+ $this->service->refresh();+ }+ public function deploy()+ {+ $this->service->parse();+ $activity = StartService::run($this->service);+ $this->emit('newMonitorActivity', $activity->id);+ }+ public function stop()+ {+ StopService::run($this->service);+ $this->service->refresh();+ }+}diff --git a/app/Http/Livewire/Project/Service/Show.php b/app/Http/Livewire/Project/Service/Show.phpnew file mode 100644index 0000000000..7a9e62df2e--- /dev/null+++ b/app/Http/Livewire/Project/Service/Show.php@@ -0,0 +1,42 @@+<?php++namespace App\Http\Livewire\Project\Service;++use App\Models\Service;+use App\Models\ServiceApplication;+use App\Models\ServiceDatabase;+use Illuminate\Support\Collection;+use Livewire\Component;++class Show extends Component+{+ public Service $service;+ public ServiceApplication $serviceApplication;+ public ServiceDatabase $serviceDatabase;+ public array $parameters;+ public array $query;+ public Collection $services;+ protected $listeners = ['generateDockerCompose'];++ public function mount()+ {+ $this->services = collect([]);+ $this->parameters = get_route_parameters();+ $this->query = request()->query();+ $this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();+ $service = $this->service->applications()->whereName($this->parameters['service_name'])->first();+ if ($service) {+ $this->serviceApplication = $service;+ } else {+ $this->serviceDatabase = $this->service->databases()->whereName($this->parameters['service_name'])->first();+ }+ }+ public function generateDockerCompose()+ {+ $this->service->parse();+ }+ public function render()+ {+ return view('livewire.project.service.show');+ }+}diff --git a/app/Http/Livewire/Project/Shared/Danger.php b/app/Http/Livewire/Project/Shared/Danger.phpindex 911192a2a1..c88ade583a 100644--- a/app/Http/Livewire/Project/Shared/Danger.php+++ b/app/Http/Livewire/Project/Shared/Danger.php@@ -19,13 +19,24 @@ class Danger extends Componentpublic function delete(){- $destination = $this->resource->destination->getMorphClass()::where('id', $this->resource->destination->id)->first();-- instant_remote_process(["docker rm -f {$this->resource->uuid}"], $destination->server);- $this->resource->delete();- return redirect()->route('project.resources', [- 'project_uuid' => $this->parameters['project_uuid'],- 'environment_name' => $this->parameters['environment_name']- ]);+ try {+ if ($this->resource->type() === 'service') {+ $server = $this->resource->server;+ } else {+ $destination = data_get($this->resource, 'destination');+ if ($destination) {+ $destination = $this->resource->destination->getMorphClass()::where('id', $this->resource->destination->id)->first();+ $server = $destination->server;+ }+ }+ instant_remote_process(["docker rm -f {$this->resource->uuid}"], $server);+ $this->resource->delete();+ return redirect()->route('project.resources', [+ 'project_uuid' => $this->parameters['project_uuid'],+ 'environment_name' => $this->parameters['environment_name']+ ]);+ } catch (\Throwable $e) {+ return handleError($e);+ }}}diff --git a/app/Http/Livewire/Project/Shared/EnvironmentVariable/Add.php b/app/Http/Livewire/Project/Shared/EnvironmentVariable/Add.phpindex cf14a894e4..af94ed77f7 100644--- a/app/Http/Livewire/Project/Shared/EnvironmentVariable/Add.php+++ b/app/Http/Livewire/Project/Shared/EnvironmentVariable/Add.php@@ -31,7 +31,6 @@ class Add extends Componentpublic function submit(){- ray('submitting');$this->validate();$this->emitUp('submit', ['key' => $this->key,diff --git a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.phpindex bdb6ab50b4..6d494e2936 100644--- a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php+++ b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php@@ -53,6 +53,7 @@ class All extends Component$this->resource->environment_variables_preview()->delete();} else {$variables = parseEnvFormatToArray($this->variables);+ ray($variables);$existingVariables = $this->resource->environment_variables();$this->resource->environment_variables()->delete();}@@ -68,11 +69,16 @@ class All extends Component$environment->value = $variable;$environment->is_build_time = false;$environment->is_preview = $isPreview ? true : false;- if ($this->resource->type() === 'application') {- $environment->application_id = $this->resource->id;- }- if ($this->resource->type() === 'standalone-postgresql') {- $environment->standalone_postgresql_id = $this->resource->id;+ switch ($this->resource->type()) {+ case 'application':+ $environment->application_id = $this->resource->id;+ break;+ case 'standalone-postgresql':+ $environment->standalone_postgresql_id = $this->resource->id;+ break;+ case 'service':+ $environment->service_id = $this->resource->id;+ break;}$environment->save();}diff --git a/app/Http/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Http/Livewire/Project/Shared/EnvironmentVariable/Show.phpindex cfc94af22b..4eaa1231c1 100644--- a/app/Http/Livewire/Project/Shared/EnvironmentVariable/Show.php+++ b/app/Http/Livewire/Project/Shared/EnvironmentVariable/Show.php@@ -10,7 +10,9 @@ class Show extends Component{public $parameters;public ModelsEnvironmentVariable $env;- public string|null $modalId = null;+ public ?string $modalId = null;+ public string $type;+protected $rules = ['env.key' => 'required|string','env.value' => 'required|string',@@ -37,6 +39,7 @@ class Show extends Component$this->validate();$this->env->save();$this->emit('success', 'Environment variable updated successfully.');+ $this->emit('refreshEnvs');}public function delete()diff --git a/app/Http/Livewire/Project/Shared/Storages/Show.php b/app/Http/Livewire/Project/Shared/Storages/Show.phpindex 7cbf322f70..84593aef31 100644--- a/app/Http/Livewire/Project/Shared/Storages/Show.php+++ b/app/Http/Livewire/Project/Shared/Storages/Show.php@@ -2,13 +2,16 @@namespace App\Http\Livewire\Project\Shared\Storages;+use App\Models\LocalPersistentVolume;use Livewire\Component;use Visus\Cuid2\Cuid2;class Show extends Component{- public $storage;- public string|null $modalId = null;+ public LocalPersistentVolume $storage;+ public bool $isReadOnly = false;+ public ?string $modalId = null;+protected $rules = ['storage.name' => 'required|string','storage.mount_path' => 'required|string',diff --git a/app/Jobs/ContainerStatusJob.php b/app/Jobs/ContainerStatusJob.phpindex e407dabdf1..5b0ca1683b 100644--- a/app/Jobs/ContainerStatusJob.php+++ b/app/Jobs/ContainerStatusJob.php@@ -170,40 +170,32 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncryptedif (in_array("$service->id-$app->name", $foundServices)) {continue;} else {- $exitedServices->push($service);- $app->update(['status' => 'exited']);+ $exitedServices->push($app);}}foreach ($dbs as $db) {if (in_array("$service->id-$db->name", $foundServices)) {continue;} else {- $exitedServices->push($service);- $db->update(['status' => 'exited']);+ $exitedServices->push($db);}}- }+ }$exitedServices = $exitedServices->unique('id');- ray($exitedServices);- // ray($exitedServices);- // foreach ($serviceIds as $serviceId) {- // $service = $services->where('id', $serviceId)->first();- // if ($service->status === 'exited') {- // continue;- // }-- // $name = data_get($service, 'name');- // $fqdn = data_get($service, 'fqdn');-- // $containerName = $name ? "$name ($fqdn)" : $fqdn;-- // $project = data_get($service, 'environment.project');- // $environment = data_get($service, 'environment');-- // $url = base_url() . '/project/' . $project->uuid . "/" . $environment->name . "/service/" . $service->uuid;+ foreach ($exitedServices as $exitedService) {+ if ($exitedService->status === 'exited') {+ continue;+ }+ $name = data_get($exitedService, 'name');+ $fqdn = data_get($exitedService, 'fqdn');+ $containerName = $name ? "$name ($fqdn)" : $fqdn;+ $project = data_get($service, 'environment.project');+ $environment = data_get($service, 'environment');- // $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url));- // }+ $url = base_url() . '/project/' . $project->uuid . "/" . $environment->name . "/service/" . $service->uuid;+ $this->server->team->notify(new ContainerStopped($containerName, $this->server, $url));+ $exitedService->update(['status' => 'exited']);+ }$notRunningApplications = $applications->pluck('id')->diff($foundApplications);foreach ($notRunningApplications as $applicationId) {diff --git a/app/Models/Service.php b/app/Models/Service.phpindex e713d51305..fb04608b89 100644--- a/app/Models/Service.php+++ b/app/Models/Service.php@@ -3,7 +3,6 @@namespace App\Models;use App\Enums\ProxyTypes;-use Illuminate\Database\Eloquent\Casts\Attribute;use Illuminate\Database\Eloquent\Factories\HasFactory;use Illuminate\Database\Eloquent\Relations\HasMany;use Illuminate\Support\Collection;@@ -14,27 +13,26 @@ class Service extends BaseModel{use HasFactory;protected $guarded = [];- public function persistentStorages()- {- return $this->morphMany(LocalPersistentVolume::class, 'resource');- }- public function portsMappingsArray(): Attribute- {- return Attribute::make(- get: fn () => is_null($this->ports_mappings)- ? []- : explode(',', $this->ports_mappings),- );+ protected static function booted()+ {+ static::deleted(function ($service) {+ foreach($service->applications()->get() as $application) {+ $application->persistentStorages()->delete();+ }+ foreach($service->databases()->get() as $database) {+ $database->persistentStorages()->delete();+ }+ $service->environment_variables()->delete();+ $service->applications()->delete();+ $service->databases()->delete();+ });}- public function portsExposesArray(): Attribute+ public function type(){- return Attribute::make(- get: fn () => is_null($this->ports_exposes)- ? []- : explode(',', $this->ports_exposes)- );+ return 'service';}+public function applications(){return $this->hasMany(ServiceApplication::class);@@ -47,10 +45,10 @@ class Service extends BaseModel{return $this->belongsTo(Environment::class);}- public function server() {+ public function server()+ {return $this->belongsTo(Server::class);}-public function byName(string $name){$app = $this->applications()->whereName($name)->first();@@ -70,7 +68,6 @@ class Service extends BaseModelpublic function parse(bool $isNew = false): Collection{// ray()->clearAll();- ray('Service parse');if ($this->docker_compose_raw) {$yaml = Yaml::parse($this->docker_compose_raw);@@ -138,8 +135,8 @@ class Service extends BaseModel}}}- $savedService->ports_exposes = $ports->implode(',');- $savedService->save();+ // $savedService->ports_exposes = $ports->implode(',');+ // $savedService->save();}// Collect volumes$serviceVolumes = collect(data_get($service, 'volumes', []));@@ -158,17 +155,38 @@ class Service extends BaseModelreturn $key == $volumeName;});if (!$volumeExists) {- if (!Str::startsWith($volumeName, '/')) {+ if (Str::startsWith($volumeName, '/')) {+ $volumes->put($volumeName, $volumePath);+ LocalPersistentVolume::updateOrCreate(+ [+ 'mount_path' => $volumePath,+ 'resource_id' => $savedService->id,+ 'resource_type' => get_class($savedService)+ ],+ [+ 'name' => Str::slug($volumeName, '-'),+ 'mount_path' => $volumePath,+ 'host_path' => $volumeName,+ 'resource_id' => $savedService->id,+ 'resource_type' => get_class($savedService)+ ]+ );+ } else {$composeVolumes->put($volumeName, null);- }- $volumes->put($volumeName, $volumePath);- if ($isNew) {- LocalPersistentVolume::create([- 'name' => $volumeName,- 'mount_path' => $volumePath,- 'resource_id' => $savedService->id,- 'resource_type' => get_class($savedService)- ]);+ LocalPersistentVolume::updateOrCreate(+ [+ 'mount_path' => $volumePath,+ 'resource_id' => $savedService->id,+ 'resource_type' => get_class($savedService)+ ],+ [+ 'name' => $volumeName,+ 'mount_path' => $volumePath,+ 'host_path' => null,+ 'resource_id' => $savedService->id,+ 'resource_type' => get_class($savedService)+ ]+ );}}}@@ -229,25 +247,26 @@ class Service extends BaseModel}if (!$envs->has($nakedName->value())) {$envs->put($nakedName->value(), $nakedValue->value());- if ($isNew) {- EnvironmentVariable::create([- 'key' => $nakedName->value(),- 'value' => $nakedValue->value(),- 'is_build_time' => false,- 'service_id' => $this->id,- 'is_preview' => false,- ]);- }+ EnvironmentVariable::updateOrCreate([+ 'key' => $nakedName->value(),+ 'service_id' => $this->id,+ ], [+ 'value' => $nakedValue->value(),+ 'is_build_time' => false,+ 'service_id' => $this->id,+ 'is_preview' => false,+ ]);}} else {if (!$envs->has($nakedName->value())) {$envs->put($nakedName->value(), null);- if ($isNew) {+ $envExists = EnvironmentVariable::where('service_id', $this->id)->where('key', $nakedName->value())->exists();+ if (!$envExists) {EnvironmentVariable::create(['key' => $nakedName->value(),'value' => null,- 'is_build_time' => false,'service_id' => $this->id,+ 'is_build_time' => false,'is_preview' => false,]);}@@ -259,31 +278,31 @@ class Service extends BaseModel$generatedValue = null;if ($variableName->startsWith('SERVICE_USER')) {$generatedValue = Str::random(10);- if ($isNew) {- if (!$envs->has($variableName->value())) {- $envs->put($variableName->value(), $generatedValue);- EnvironmentVariable::create([- 'key' => $variableName->value(),- 'value' => $generatedValue,- 'is_build_time' => false,- 'service_id' => $this->id,- 'is_preview' => false,- ]);- }+ if (!$envs->has($variableName->value())) {+ $envs->put($variableName->value(), $generatedValue);+ EnvironmentVariable::updateOrCreate([+ 'key' => $variableName->value(),+ 'service_id' => $this->id,+ ], [+ 'value' => $generatedValue,+ 'is_build_time' => false,+ 'service_id' => $this->id,+ 'is_preview' => false,+ ]);}} else if ($variableName->startsWith('SERVICE_PASSWORD')) {$generatedValue = Str::password(symbols: false);- if ($isNew) {- if (!$envs->has($variableName->value())) {- $envs->put($variableName->value(), $generatedValue);- EnvironmentVariable::create([- 'key' => $variableName->value(),- 'value' => $generatedValue,- 'is_build_time' => false,- 'service_id' => $this->id,- 'is_preview' => false,- ]);- }+ if (!$envs->has($variableName->value())) {+ $envs->put($variableName->value(), $generatedValue);+ EnvironmentVariable::updateOrCreate([+ 'key' => $variableName->value(),+ 'service_id' => $this->id,+ ], [+ 'value' => $generatedValue,+ 'is_build_time' => false,+ 'service_id' => $this->id,+ 'is_preview' => false,+ ]);}} else if ($variableName->startsWith('SERVICE_FQDN')) {if ($fqdn) {@@ -324,20 +343,6 @@ class Service extends BaseModeldata_forget($service, 'documentation');return $service;});- // $services = $services->map(function ($service, $serviceName) {- // $dependsOn = collect(data_get($service, 'depends_on', []));- // $dependsOn = $dependsOn->map(function ($value) {- // return "$value-{$this->uuid}";- // });- // data_set($service, 'depends_on', $dependsOn->toArray());- // return $service;- // });- // $renamedServices = collect([]);- // collect($services)->map(function ($service, $serviceName) use ($renamedServices) {- // $newServiceName = "$serviceName-$this->uuid";- // $renamedServices->put($newServiceName, $service);- // });-$finalServices = ['version' => $dockerComposeVersion,'services' => $services->toArray(),diff --git a/app/Models/ServiceApplication.php b/app/Models/ServiceApplication.phpindex df506468c3..79b96c0b29 100644--- a/app/Models/ServiceApplication.php+++ b/app/Models/ServiceApplication.php@@ -2,6 +2,7 @@namespace App\Models;+use Illuminate\Database\Eloquent\Casts\Attribute;use Illuminate\Database\Eloquent\Factories\HasFactory;class ServiceApplication extends BaseModel@@ -9,4 +10,12 @@ class ServiceApplication extends BaseModeluse HasFactory;protected $guarded = [];+ public function type()+ {+ return 'service';+ }+ public function persistentStorages()+ {+ return $this->morphMany(LocalPersistentVolume::class, 'resource');+ }}diff --git a/app/Models/ServiceDatabase.php b/app/Models/ServiceDatabase.phpindex 774753eeb0..dc0d857425 100644--- a/app/Models/ServiceDatabase.php+++ b/app/Models/ServiceDatabase.php@@ -9,4 +9,12 @@ class ServiceDatabase extends BaseModeluse HasFactory;protected $guarded = [];+ public function type()+ {+ return 'service';+ }+ public function persistentStorages()+ {+ return $this->morphMany(LocalPersistentVolume::class, 'resource');+ }}diff --git a/app/View/Components/Services/Links.php b/app/View/Components/Services/Links.phpnew file mode 100644index 0000000000..e36d52d57a--- /dev/null+++ b/app/View/Components/Services/Links.php@@ -0,0 +1,29 @@+<?php++namespace App\View\Components\Services;++use App\Models\Service;+use Closure;+use Illuminate\Contracts\View\View;+use Illuminate\Support\Collection;+use Illuminate\View\Component;++class Links extends Component+{+ public Collection $links;+ public function __construct(public Service $service)+ {+ $this->links = collect([]);+ $service->applications()->get()->map(function ($application) {+ $this->links->push($application->fqdn);+ });+ }++ /**+ * Get the view / contents that represent the component.+ */+ public function render(): View|Closure|string+ {+ return view('components.services.links');+ }+}diff --git a/bootstrap/helpers/docker.php b/bootstrap/helpers/docker.phpindex 123e9fb9f2..90609af23a 100644--- a/bootstrap/helpers/docker.php+++ b/bootstrap/helpers/docker.php@@ -132,7 +132,6 @@ function get_port_from_dockerfile($dockerfile): intfunction defaultLabels($id, $name, $pull_request_id = 0, string $type = 'application'){- ray($type);$labels = collect([]);$labels->push('coolify.managed=true');$labels->push('coolify.version=' . config('version'));diff --git a/database/migrations/2023_09_20_082733_create_service_databases_table.php b/database/migrations/2023_09_20_082733_create_service_databases_table.phpindex 0b7a06dd94..924c663ba9 100644--- a/database/migrations/2023_09_20_082733_create_service_databases_table.php+++ b/database/migrations/2023_09_20_082733_create_service_databases_table.php@@ -15,12 +15,10 @@ return new class extends Migration$table->id();$table->string('uuid')->unique();$table->string('name');+ $table->string('human_name')->nullable();$table->string('status')->default('exited');- $table->string('ports_exposes')->nullable();- $table->string('ports_mappings')->nullable();-$table->foreignId('service_id');$table->timestamps();});diff --git a/database/migrations/2023_09_20_082737_create_service_applications_table.php b/database/migrations/2023_09_20_082737_create_service_applications_table.phpindex 1c1f0edb7c..c4c363ed54 100644--- a/database/migrations/2023_09_20_082737_create_service_applications_table.php+++ b/database/migrations/2023_09_20_082737_create_service_applications_table.php@@ -15,24 +15,10 @@ return new class extends Migration$table->id();$table->string('uuid')->unique();$table->string('name');+ $table->string('human_name')->nullable();$table->string('fqdn')->unique()->nullable();- $table->string('ports_exposes')->nullable();- $table->string('ports_mappings')->nullable();-- $table->string('health_check_path')->default('/');- $table->string('health_check_port')->nullable();- $table->string('health_check_host')->default('localhost');- $table->string('health_check_method')->default('GET');- $table->integer('health_check_return_code')->default(200);- $table->string('health_check_scheme')->default('http');- $table->string('health_check_response_text')->nullable();- $table->integer('health_check_interval')->default(5);- $table->integer('health_check_timeout')->default(5);- $table->integer('health_check_retries')->default(10);- $table->integer('health_check_start_period')->default(5);-$table->string('status')->default('exited');$table->foreignId('service_id');diff --git a/resources/views/components/applications/links.blade.php b/resources/views/components/applications/links.blade.phpindex 9e90c9b2bc..0519d339ee 100644--- a/resources/views/components/applications/links.blade.php+++ b/resources/views/components/applications/links.blade.php@@ -1,18 +1,20 @@<div class="group">- <label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Links+ <label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Open Application<x-chevron-down /></label><div class="absolute hidden group-hover:block"><ul tabindex="0" class="relative -ml-24 text-xs text-white normal-case rounded min-w-max menu bg-coolgray-200">- <li>- <a target="_blank"- class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"- href="{{ $application->gitBranchLocation }}">- <x-git-icon git="{{ $application->source?->getMorphClass() }}" />- Git Repository- </a>- </li>+ @if (data_get($application, 'gitBrancLocation'))+ <li>+ <a target="_blank"+ class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"+ href="{{ $application->gitBranchLocation }}">+ <x-git-icon git="{{ $application->source?->getMorphClass() }}" />+ Git Repository+ </a>+ </li>+ @endif@if (data_get($application, 'fqdn'))@foreach (Str::of(data_get($application, 'fqdn'))->explode(',') as $fqdn)<li>@@ -31,7 +33,7 @@</li>@endforeach@endif- @if (data_get($application, 'previews')->count() > 0)+ @if (data_get($application, 'previews', collect([]))->count() > 0)@foreach (data_get($application, 'previews') as $preview)@if (data_get($preview, 'fqdn'))<li>diff --git a/resources/views/components/services/links.blade.php b/resources/views/components/services/links.blade.phpnew file mode 100644index 0000000000..0a23e001fe--- /dev/null+++ b/resources/views/components/services/links.blade.php@@ -0,0 +1,28 @@+<div class="group">+ <label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Open Application+ <x-chevron-down />+ </label>++ <div class="absolute hidden group-hover:block">+ <ul tabindex="0" class="relative -ml-24 text-xs text-white normal-case rounded min-w-max menu bg-coolgray-200">+ @if ($links->count() > 0)+ @foreach ($links as $link)+ <li>+ <a class="text-xs text-white rounded-none hover:no-underline hover:bg-coollabs hover:text-white"+ target="_blank" href="{{ $link }}">+ <svg xmlns="http://www.w3.org/2000/svg" class="w-6 h-6" viewBox="0 0 24 24"+ stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"+ stroke-linejoin="round">+ <path stroke="none" d="M0 0h24v24H0z" fill="none" />+ <path d="M9 15l6 -6" />+ <path d="M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464" />+ <path+ d="M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463" />+ </svg>{{ $link }}+ </a>+ </li>+ @endforeach+ @endif+ </ul>+ </div>+</div>diff --git a/resources/views/components/services/navbar.blade.php b/resources/views/components/services/navbar.blade.phpindex da5b475624..98a4a23342 100644--- a/resources/views/components/services/navbar.blade.php+++ b/resources/views/components/services/navbar.blade.php@@ -1,13 +1,11 @@<div class="navbar-main"><a class="{{ request()->routeIs('project.service') ? 'text-white' : '' }}"- href="{{ route('project.service', $parameters) }}">- <button>Configuration</button>+ href="{{ route('project.service', [...$parameters, 'service_name' => null]) }}">+ <button>Service</button></a>+ <x-services.links :service="$service" /><div class="flex-1"></div>- {{-- <x-applications.links :application="$application" />-- <x-applications.advanced :application="$application" /> --}}- @if (serviceStatus($service) !== 'exited')+ @if (serviceStatus($service) === 'running')<button wire:click='stop' class="flex items-center gap-2 cursor-pointer hover:text-white text-neutral-400"><svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-error" viewBox="0 0 24 24" stroke-width="2"stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">@@ -17,7 +15,7 @@</svg>Stop</button>- @else+ @elseif(serviceStatus($service) === 'exited')<button wire:click='deploy' onclick="startService.showModal()"class="flex items-center gap-2 cursor-pointer hover:text-white text-neutral-400"><svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-warning" viewBox="0 0 24 24" stroke-width="1.5"@@ -27,5 +25,25 @@</svg>Deploy</button>+ @elseif (serviceStatus($service) === 'degraded')+ <button wire:click='deploy' onclick="startService.showModal()"+ class="flex items-center gap-2 cursor-pointer hover:text-white text-neutral-400">+ <svg class="w-5 h-5 text-warning" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">+ <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">+ <path d="M19.933 13.041a8 8 0 1 1-9.925-8.788c3.899-1 7.935 1.007 9.425 4.747" />+ <path d="M20 4v5h-5" />+ </g>+ </svg>+ Restart Degraded Services+ </button>+ <button wire:click='stop' class="flex items-center gap-2 cursor-pointer hover:text-white text-neutral-400">+ <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-error" viewBox="0 0 24 24" stroke-width="2"+ stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>+ <path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"></path>+ <path d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"></path>+ </svg>+ Stop+ </button>@endif</div>diff --git a/resources/views/livewire/project/service/application.blade.php b/resources/views/livewire/project/service/application.blade.phpnew file mode 100644index 0000000000..b7e0a62ffd--- /dev/null+++ b/resources/views/livewire/project/service/application.blade.php@@ -0,0 +1,14 @@+<form wire:submit.prevent='submit'>+ <div class="flex 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>+ </div>+ <div class="flex gap-2">+ <x-forms.input label="Name" id="application.human_name" placeholder="Name"></x-forms.input>+ <x-forms.input label="FQDN" required id="application.fqdn"></x-forms.input>+ </div>+</form>diff --git a/resources/views/livewire/project/service/database.blade.php b/resources/views/livewire/project/service/database.blade.phpnew file mode 100644index 0000000000..16f49743c8--- /dev/null+++ b/resources/views/livewire/project/service/database.blade.php@@ -0,0 +1,13 @@+<form wire:submit.prevent='submit'>+ <div class="flex gap-2 pb-4">+ @if ($database->human_name)+ <h2>{{ Str::headline($database->human_name) }}</h2>+ @else+ <h2>{{ Str::headline($database->name) }}</h2>+ @endif+ <x-forms.button type="submit">Save</x-forms.button>+ </div>+ <div class="flex gap-2">+ <x-forms.input label="Name" id="database.human_name" placeholder="Name"></x-forms.input>+ </div>+</form>diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.phpindex b833c8d7f9..cef5d93706 100644--- a/resources/views/livewire/project/service/index.blade.php+++ b/resources/views/livewire/project/service/index.blade.php@@ -1,25 +1,79 @@-<div x-init="$wire.check_status">- <livewire:project.service.modal />- <h1>Configuration</h1>- <x-resources.breadcrumbs :resource="$service" :parameters="$parameters" />- <x-services.navbar :service="$service" :parameters="$parameters" />- <h3>Applications</h3>- @foreach ($service->applications as $application)- <form class="box" wire:submit.prevent='submit'>- <p>{{ $application->name }}</p>- <x-forms.input id="services.{{ $application->name }}.fqdn"></x-forms.input>- <x-forms.button type="submit">Save</x-forms.button>- </form>- @endforeach- @if ($service->databases->count() > 0)- <h3>Databases</h3>- @endif- @foreach ($service->databases as $database)- <p>{{ $database->name }}</p>- <p>{{ $database->status }}</p>- @endforeach- <h3>Variables</h3>- @foreach ($service->environment_variables as $variable)- <p>{{ $variable->key }}={{ $variable->value }}</p>- @endforeach-</div>+<div x-data="{ raw: true, activeTab: window.location.hash ? window.location.hash.substring(1) : 'service-stack' }">+ <livewire:project.service.navbar :service="$service" :parameters="$parameters" :query="$query" />+ <div class="flex h-full pt-6">+ <div class="flex flex-col gap-4 min-w-fit">+ <a :class="activeTab === 'service-stack' && 'text-white'"+ @click.prevent="activeTab = 'service-stack'; window.location.hash = 'service-stack'" href="#">Service Stack</a>+ <a :class="activeTab === 'compose' && 'text-white'"+ @click.prevent="activeTab = 'compose'; window.location.hash = 'compose'" href="#">Compose File</a>+ <a :class="activeTab === 'environment-variables' && 'text-white'"+ @click.prevent="activeTab = 'environment-variables'; window.location.hash = 'environment-variables'"+ href="#">Environment+ Variables</a>+ <a :class="activeTab === 'danger' && 'text-white'"+ @click.prevent="activeTab = 'danger'; window.location.hash = 'danger'" href="#">Danger Zone+ </a>+ </div>+ <div class="w-full pl-8">+ <div x-cloak x-show="activeTab === 'service-stack'">+ <h2 class="pb-4"> Service Stack </h2>+ <div class="grid grid-cols-1 gap-2">+ @foreach ($service->applications as $application)+ <a class="flex flex-col justify-center box"+ href="{{ route('project.service.show', [...$parameters, 'service_name' => $application->name]) }}">+ @if ($application->human_name)+ {{ Str::headline($application->human_name) }}+ @else+ {{ Str::headline($application->name) }}+ @endif+ @if ($application->fqdn)+ <span class="text-xs">{{ $application->fqdn }}</span>+ @endif+ </a>+ @endforeach+ @foreach ($service->databases as $database)+ <a class="justify-center box"+ href="{{ route('project.service.show', [...$parameters, 'service_name' => $database->name]) }}">+ @if ($database->human_name)+ {{ Str::headline($database->human_name) }}+ @else+ {{ Str::headline($database->name) }}+ @endif+ </a>+ @endforeach+ </div>+ </div>+ <div x-cloak x-show="activeTab === 'compose'">+ <div x-cloak x-show="activeTab === 'compose'">+ <div class="flex gap-2 pb-4">+ <h2>Docker Compose</h2>+ <div x-cloak x-show="raw">+ <x-forms.button class="w-64" @click.prevent="raw = !raw">Show Deployable</x-forms.button>+ <x-forms.button wire:click='save'>Save</x-forms.button>+ </div>+ <div x-cloak x-show="raw === false">+ <x-forms.button class="w-64" @click.prevent="raw = !raw">Show Source</x-forms.button>+ <x-forms.button disabled wire:click='save'>Save</x-forms.button>++ </div>+ </div>+ <div x-cloak x-show="raw">+ <x-forms.textarea rows="20" id="service.docker_compose_raw">+ </x-forms.textarea>+ </div>+ <div x-cloak x-show="raw === false">+ <x-forms.textarea readonly rows="20" id="service.docker_compose">+ </x-forms.textarea>+ </div>+ </div>+ </div>+ <div x-cloak x-show="activeTab === 'environment-variables'">+ <div x-cloak x-show="activeTab === 'environment-variables'">+ <livewire:project.shared.environment-variable.all :resource="$service" />+ </div>+ </div>+ <div x-cloak x-show="activeTab === 'danger'">+ <livewire:project.shared.danger :resource="$service" />+ </div>+ </div>+ </div>diff --git a/resources/views/livewire/project/service/navbar.blade.php b/resources/views/livewire/project/service/navbar.blade.phpnew file mode 100644index 0000000000..d18838ccef--- /dev/null+++ b/resources/views/livewire/project/service/navbar.blade.php@@ -0,0 +1,6 @@+<div x-init="$wire.check_status">+ <livewire:project.service.modal />+ <h1>Configuration</h1>+ <x-resources.breadcrumbs :resource="$service" :parameters="$parameters" />+ <x-services.navbar :service="$service" :parameters="$parameters" />+</div>diff --git a/resources/views/livewire/project/service/show.blade.php b/resources/views/livewire/project/service/show.blade.phpnew file mode 100644index 0000000000..7793777c4a--- /dev/null+++ b/resources/views/livewire/project/service/show.blade.php@@ -0,0 +1,30 @@+<div x-data="{ activeTab: window.location.hash ? window.location.hash.substring(1) : 'general' }">+ <livewire:project.service.navbar :service="$service" :parameters="$parameters" :query="$query" />+ <div class="flex h-full pt-6">+ <div class="flex flex-col gap-4 min-w-fit">+ <a :class="activeTab === 'general' && 'text-white'"+ @click.prevent="activeTab = 'general'; window.location.hash = 'general'" href="#">General</a>+ <a :class="activeTab === 'storages' && 'text-white'"+ @click.prevent="activeTab = 'storages'; window.location.hash = 'storages'" href="#">Storages+ </a>+ </div>+ <div class="w-full pl-8">+ @isset($serviceApplication)+ <div x-cloak x-show="activeTab === 'general'" class="h-full">+ <livewire:project.service.application :application="$serviceApplication" />+ </div>+ <div x-cloak x-show="activeTab === 'storages'">+ <livewire:project.shared.storages.all :resource="$serviceApplication" />+ </div>+ @endisset+ @isset($serviceDatabase)+ <div x-cloak x-show="activeTab === 'general'" class="h-full">+ <livewire:project.service.database :database="$serviceDatabase" />+ </div>+ <div x-cloak x-show="activeTab === 'storages'">+ <livewire:project.shared.storages.all :resource="$serviceDatabase" />+ </div>+ @endisset+ </div>+ </div>+</div>diff --git a/resources/views/livewire/project/shared/environment-variable/all.blade.php b/resources/views/livewire/project/shared/environment-variable/all.blade.phpindex 9ffb6b2174..fe9788fa6d 100644--- a/resources/views/livewire/project/shared/environment-variable/all.blade.php+++ b/resources/views/livewire/project/shared/environment-variable/all.blade.php@@ -12,7 +12,7 @@@if ($view === 'normal')@forelse ($resource->environment_variables as $env)<livewire:project.shared.environment-variable.show wire:key="environment-{{ $env->id }}"- :env="$env" />+ :env="$env" :type="$resource->type()" />@empty<div class="text-neutral-500">No environment variables found.</div>@endforelse@@ -23,12 +23,12 @@</div>@foreach ($resource->environment_variables_preview as $env)<livewire:project.shared.environment-variable.show wire:key="environment-{{ $env->id }}"- :env="$env" />+ :env="$env" :type="$resource->type()" />@endforeach@endif@else<form wire:submit.prevent='saveVariables(false)' class="flex flex-col gap-2">- <x-forms.textarea rows=5 class="whitespace-pre-wrap" label="Environment Variables"+ <x-forms.textarea rows=5 class="whitespace-pre-wrap"id="variables"></x-forms.textarea><x-forms.button type="submit" class="btn btn-primary">Save</x-forms.button></form>diff --git a/resources/views/livewire/project/shared/environment-variable/show.blade.php b/resources/views/livewire/project/shared/environment-variable/show.blade.phpindex 6c74ceb37d..4f1d4919eb 100644--- a/resources/views/livewire/project/shared/environment-variable/show.blade.php+++ b/resources/views/livewire/project/shared/environment-variable/show.blade.php@@ -8,7 +8,9 @@<form wire:submit.prevent='submit' class="flex flex-col items-center gap-2 xl:flex-row"><x-forms.input id="env.key" /><x-forms.input type="password" id="env.value" />- <x-forms.checkbox instantSave id="env.is_build_time" label="Build Variable?" />+ @if ($type !== 'service')+ <x-forms.checkbox instantSave id="env.is_build_time" label="Build Variable?" />+ @endif<div class="flex gap-2"><x-forms.button type="submit">Updatediff --git a/resources/views/livewire/project/shared/storages/all.blade.php b/resources/views/livewire/project/shared/storages/all.blade.phpindex 1287aaf0cb..32cd5d2996 100644--- a/resources/views/livewire/project/shared/storages/all.blade.php+++ b/resources/views/livewire/project/shared/storages/all.blade.php@@ -2,18 +2,25 @@<div><div class="flex items-center gap-2"><h2>Storages</h2>- <x-helper- helper="For Preview Deployments, storage has a <span class='text-helper'>-pr-#PRNumber</span> in their+ @if ($resource->type() !== 'service')+ <x-helper+ helper="For Preview Deployments, storage has a <span class='text-helper'>-pr-#PRNumber</span> in theirvolumename, example: <span class='text-helper'>-pr-1</span>" />- <x-forms.button class="btn" onclick="newStorage.showModal()">+ Add</x-forms.button>- <livewire:project.shared.storages.add />+ <x-forms.button class="btn" onclick="newStorage.showModal()">+ Add</x-forms.button>+ <livewire:project.shared.storages.add />+ @endif</div><div>Persistent storage to preserve data between deployments.</div></div><div class="flex flex-col gap-2 py-4">@forelse ($resource->persistentStorages as $storage)- <livewire:project.shared.storages.show wire:key="storage-{{ $storage->id }}" :storage="$storage" />+ @if ($resource->type() === 'service')+ <livewire:project.shared.storages.show wire:key="storage-{{ $storage->id }}" :storage="$storage"+ isReadOnly='true' />+ @else+ <livewire:project.shared.storages.show wire:key="storage-{{ $storage->id }}" :storage="$storage" />+ @endif@empty<div class="text-neutral-500">No storages found.</div>@endforelsediff --git a/resources/views/livewire/project/shared/storages/show.blade.php b/resources/views/livewire/project/shared/storages/show.blade.phpindex dcdc951510..23714d74df 100644--- a/resources/views/livewire/project/shared/storages/show.blade.php+++ b/resources/views/livewire/project/shared/storages/show.blade.php@@ -6,8 +6,11 @@reversible. <br>Please think again.</p></x-slot:modalBody></x-modal>- <form wire:submit.prevent='submit' class="flex flex-col gap-2 xl:items-end xl:flex-row">- @if ($storage->is_readonly)+ @if ($isReadOnly)+ <span class="text-warning">Please modify storage layout in your Compose file.</span>+ @endif+ <form wire:submit.prevent='submit' class="flex flex-col gap-2 pt-4 xl:items-end xl:flex-row">+ @if ($isReadOnly)<x-forms.input id="storage.name" label="Name" required readonly /><x-forms.input id="storage.host_path" label="Source Path" readonly /><x-forms.input id="storage.mount_path" label="Destination Path" required readonly />@@ -15,7 +18,7 @@<x-forms.button type="submit" disabled>Update</x-forms.button>- <x-forms.button isError isModal modalId="{{ $modalId }}" disabled>+ <x-forms.button isError isModal modalId="{{ $modalId }}">Delete</x-forms.button></div>diff --git a/routes/web.php b/routes/web.phpindex 82c760a083..ada529100f 100644--- a/routes/web.php+++ b/routes/web.php@@ -8,6 +8,7 @@ use App\Http\Controllers\ProjectController;use App\Http\Controllers\ServerController;use App\Http\Livewire\Boarding\Index as BoardingIndex;use App\Http\Livewire\Project\Service\Index as ServiceIndex;+use App\Http\Livewire\Project\Service\Show as ServiceShow;use App\Http\Livewire\Dashboard;use App\Http\Livewire\Server\All;use App\Http\Livewire\Server\Show;@@ -86,6 +87,7 @@ Route::middleware(['auth'])->group(function () {// ServicesRoute::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}', ServiceIndex::class)->name('project.service');+ Route::get('/project/{project_uuid}/{environment_name}/service/{service_uuid}/{service_name}', ServiceShow::class)->name('project.service.show');});Route::middleware(['auth'])->group(function () {